Between Date()-#07:00:00# And Date()+#17:00:00#

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

The above query will return all the records in a table
since 5pm yesterday (Sunday). I need to modify it so it
will start from 5pm Friday. What is the correct syntax so
that the Date() part actually refers to say 3 days ago?
 
The above query will return all the records in a table
since 5pm yesterday (Sunday). I need to modify it so it
will start from 5pm Friday. What is the correct syntax so
that the Date() part actually refers to say 3 days ago?

What if Friday was a company holiday? Do you want from the previous
Friday on Mondays, but the previous day on other days of the week?
What about holidays in the middle of the week?

To directly answer your question: To get 5 pm on the previous Friday
if today is Monday, and 5pm yesterday otherwise, try:

DateAdd("h", 19, DateAdd("d", IIF(Weekday(Date()) = 2, -3, -1)))

I'd use the DateAdd function rather than adding and subtracting
date/time constants.
 
Back
Top