Date (Stupid Question)

  • Thread starter Thread starter Tim
  • Start date Start date
T

Tim

This should be easy, but I've got "brainfreeze"....
What's the correct syntax to get records with a date
Between today and 7 days ago??
 
This is an example of something I just used today from within a query:
# Days Past Due: DateDiff("d",[Invoice Date],Now())

All you need to do is add <7 into your criteria...
 
Beware that this is not as efficient as it could be since the DateDiff
function is executed for *every* Record in the Source Table.

See my reply to the O.P.
 
This depends whether the DateField has non-zero time component or not. If
the Field stores date-only, you can use:

WHERE [DateField]
BETWEEN DateAdd("d", -7, Date()) AND Date()

If the Field stores non-zero time component, use:

WHERE [DateField]
BETWEEN DateAdd("d", -7, Date()) AND Now()

assuming you want Records up to now. If you want Records up to the end of
the day (23:59:59), use:

WHERE ([DateField] >= DateAdd("d", -7, Date()))
AND ([DateField] < DateAdd("d", 1, Date()))
 
Thanks Van!
Van T. Dinh said:
This depends whether the DateField has non-zero time component or not. If
the Field stores date-only, you can use:

WHERE [DateField]
BETWEEN DateAdd("d", -7, Date()) AND Date()

If the Field stores non-zero time component, use:

WHERE [DateField]
BETWEEN DateAdd("d", -7, Date()) AND Now()

assuming you want Records up to now. If you want Records up to the end of
the day (23:59:59), use:

WHERE ([DateField] >= DateAdd("d", -7, Date()))
AND ([DateField] < DateAdd("d", 1, Date()))

--
HTH
Van T. Dinh
MVP (Access)





Tim said:
This should be easy, but I've got "brainfreeze"....
What's the correct syntax to get records with a date
Between today and 7 days ago??
 
Back
Top