I missed the fact that it was noon instead of midnight. But that is why testing is so important.
Create (or use a current form) and add a text box.
I set up the text box:
Tab Other - NAME = "TheDate"
Tab DATA -Input Mask = 99/99/0000;0;_
Tab FORMAT - Format = Short Date
Replace "Date()" with "Forms!FormName.TheDate" (but replace "FormName" with your form name)
Note that the form must be open when the query is executed.
Note the parenthesis:
Code:
Between ([forms]![Form2].[TheDate]-2)+#12/30/1899 12:0:0# And ([forms]![Form2].[TheDate]-1)+#12/30/1899 23:59:0#)
This is the query
Code:
SELECT DISTINCT [ITXM BLOOD Data].MRN, Format([IMGC IMAGE Data].[ImageDate]+[IMGC IMAGE Data].[ImageTime],"mm/dd/yy hh:nn") AS [CXR Image D/T] FROM ([ITXM BLOOD Data] INNER JOIN [IMGC IMAGE Data] ON [ITXM BLOOD Data].MRN = [IMGC IMAGE Data].MRN) INNER JOIN ITxM_Data ON [IMGC IMAGE Data].MRN = ITxM_Data.MRN WHERE ((([ITXM Blood Data].[IssuedDate]+[ITXM Blood Data].[IssuedTime]) Between ([forms]![Form2].[TheDate]-2)+#12/30/1899 12:0:0# And ([forms]![Form2].[TheDate]-1)+#12/30/1899 23:59:0#) AND (([IMGC IMAGE Data].[ImageDate]+[IMGC IMAGE Data].[ImageTime]) Between ([forms]![Form2].[TheDate]-2)+#12/30/1899 23:45:0# And ([forms]![Form2].[TheDate]-1)+#12/30/1899 23:59:0#) AND ((DateDiff("n",[ITXM BLOOD Data].[IssuedDate]+[ITXM BLOOD Data].[IssuedTime],[IMGC IMAGE Data].[ImageDate]+[IMGC IMAGE Data].[ImageTime])) Between 0 And 751)) ORDER BY [ITXM BLOOD Data].MRN, Format([IMGC IMAGE Data].[ImageDate]+[IMGC IMAGE Data].[ImageTime],"mm/dd/yy hh:nn");
Just enter the correct date in the text box "TheDate" and execute the query......
I don't know how 12/30/1899 12:0:0# gets in there.
Date stuff
---------------
When you enter only a date into a Date/Time field, the Time component defaults to "00:00:00" (aka midnight)
When you enter only a time into a Date/Time field, the Date component defaults to the earliest date, which MS set at "12/30/1899"
Access has a field type "Date/Time", which is actually a double precision number. Access displays the number as a date/time.
The number to the left of the decimal is the number of days from the beginning date (remember the "12/30/1899"??). The number to the right of the decimal is the portion of the day. So noon (12:00PM) is 12/24, which is .5 of a day. Or if you want to use minutes, a day has 1440 minutes, therefore noon is 720 minutes of a day.
If you want to know what portion of a day 11:59PM is, use 1439/1440. This is approx 0.999305.
11:45PM is approx 0.989583 of a day.
Why is this important? You can do date math: if you want to add one day to a date you can use Date()+1.
If you want to add half a day (12 hours), you can use date()+ 0.5.
So, instead of
Code:
Between ([forms]![Form2].[TheDate]-2)+#12/30/1899 12:0:0# And ([forms]![Form2].[TheDate]-1)+#12/30/1899 23:59:0#)
you can/could use
Code:
Between ([forms]![Form2].[TheDate]-2)+ 0.5 And ([forms]![Form2].[TheDate]-1)+ 0.999305)