Drew said:
I am trying to take todays date and subtract 30 days from it and display
all records for the days within that time frame. I have tried several
different methods and get errors or nothing at all. Can anyone help with
the correct format by which this can be done. Thank You in Advance.
If there is no such thing as a record with a date greater then today...
SELECT * FROM YourTableName
WHERE YourDateField >= DateAdd("d", -30, Date())
or
SELECT * FROM YourTableName
WHERE YourDateField >= Date()-30
If there can be records with dates greater than today...
SELECT * FROM YourTableName
WHERE YourDateField >= DateAdd("d", -30, Date())
AND YourDateField < DateAdd("d", 1, Date())
or
SELECT * FROM YourTableName
WHERE YourDateField >= Date()-30
AND YourDateField < Date()+1
DateAdd is a bit "cleaner" and more versatile if you need increments other
than days. The simple addition and subtraction syntax works because
internally Dates are stored as Double numeric types with the integer
portion representing whole days since 12/30/1899. So adding a number to a
date "works" but is sometimes frowned upon since it is relying on how data
is internally stored rather than being more explicit.