Question : How to determine if record created in a specific time interval in MS Access

In my Access database, I have a table with a column "DateTimeNotified" where I store Date/Time in the format "MM/DD/YYYY HH:MM;SS AM/PM", for example "8/23/2010 12:55:58 AM". On a report, on any given day, I want to find out how many records were created between Now() and yesterday after 7pm. I am building my query in VBA as:

SQL = "SELECT HOSPITAL, COUNT(*) AS HOSPITALCOUNT FROM tblPatient WHERE DATETIMENOTIFIED BETWEEN #" & Forms!frmreports!txtShiftStartDate & " " & TimeSerial(19, 0, 0
      "# And NOW() GROUP BY HOSPITAL"
So if run today on 8/24/2010, the SQL would build as:
SELECT HOSPITAL, COUNT(*) AS HOSPITALCOUNT FROM tblPatient WHERE DATETIMENOTIFIED BETWEEN #8/23/2010 7:00:00 PM# And NOW() GROUP BY HOSPITAL

Problem is NO records are returned even though there are actual records. However, if I remove the Time field, ie, the "7:00:00 PM" piece, it works just fine. In other words if the statement reads as: WHERE DATETIMENOTIFIED BETWEEN #8/23/2010# And NOW(), it returns records. Please help.


Answer : How to determine if record created in a specific time interval in MS Access

datasolutionz,

You used as an example of DATETIMENOTIFIED:

8/23/2010 12:55:58 AM

That value is NOT between 8/23/2010 7:00:00 PM And 8/24/2010 1:07:00 PM (what Now() resolves to for me right now).

Perhaps the reason why your query returned no records is a simple one: that no records existed that met your criteria :)

Patrick
Random Solutions  
 
programming4us programming4us