Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Query between yesterday 6AM and today 6AM

Status
Not open for further replies.

mikelev

Technical User
Mar 23, 2004
223
US
I have a report based on a query. I have 'Date()' in the criteria field which works great for selecting records created today.

Can someone provide an alternate criteria that will select between yesterday 6AM and today 6AM (or the current time)?


Cheers,



 
Assuming your field contains date and time, this should do it:

Code:
between (Date()-1 & " " & #6:00AM#) and (Date() & " " & #6:00AM#)



HTH,
Bob [morning]
 
Try this:

Code:
WHERE [[i][red]yourdatefield[/red][/i]] between ((Date()-1) + TimeSerial(18,0,0)) and (Date() + TimeSerial(6,0,0))

If you want to use the current time for the second date/time value then use the following:

Code:
WHERE [[i][red]yourdatefield[/red][/i]] between ((Date()-1) + TimeSerial(18,0,0)) and (Date()+ Time())

Post back with any questions.

[COLOR=006633]Bob Scriver[/color]
MIState1.gif
[COLOR=white 006633]MSU Spartan[/color]
 
Sorry, I misread that one. Forget the PM part. Change it to AM.

Code:
WHERE [yourdatefield] between ((Date()-1) + TimeSerial(6,0,0)) and (Date() + TimeSerial(6,0,0))

[COLOR=006633]Bob Scriver[/color]
MIState1.gif
[COLOR=white 006633]MSU Spartan[/color]
 
between (Date()-1 & " " & #6:00AM#) and (Date() & " " & #6:00AM#)

Works perfect thanks to you both!
 
Every now and again, the Hawkeyes actually beat the Spartans...

(In this case, it's more of a tie.
Shades of MSU versus Notre Dame many years ago.)

Bob
 
Off subject here, but I was there 10-10 what a whimp Ara was. Wouldn't go for it at the end and let the clock run out. Notre Dame fans were hanging their heads that day.

[COLOR=006633]Bob Scriver[/color]
MIState1.gif
[COLOR=white 006633]MSU Spartan[/color]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top