Thread: Need Help on a Formula to subtract 30 days from Current Date

1. Registered User
Join Date
Sep 2008
Posts
151

Unanswered: Need Help on a Formula to subtract 30 days from Current Date

Hello,

I am trying to add a formula to a criteria that basically subtracts 30 days from the current day.

How can I add something like this "=TODAY()-T5" to a query in Microsoft Access 2010.

Sample:
1/4/2016 minus 30 days from today 1/17/2016 = 13

If I am doing it correctly in Excel, I get 13 days for the answer.

Join Date
Feb 2004
Location
New Zealand
Posts
1,482
Look up

3. Registered User
Join Date
Sep 2008
Posts
151
Hi Myle,

Thank you so much for your response. I think I did not explain myself correctly.

I would like to query a field for dates less than 30 days. So, if I have a field called Enter date and I only want to see the output of dates that are not older than 30 days from today (1/17/16), what formula would I use? See example below:

Field:
Enter date
1/1/16
5/1/16
1/29/16

Output:
Enter date
1/1/16
1/29/16

The output should be 1/1/16 and 1/29/16 because they are the only dates within the 30 day window.

Do I use the same formula that you graciously provided?

Join Date
Nov 2004
Location
out on a limb
Posts
13,692
So your query needs a where clause
Code:
`WHERE mydatecolumn > dateadd ("d", -30, date ())`
Replace mydatecolumn with the name of the column containing the date values you are interested in
If you use the query designer (I don't, so this may not be right) in the criteria cell for the date column use the above EXCLUDING the ' WHERE mydatecolumn' bit
You can take advantage of a quirk of the way Access / JET handles dates, but you shouldn't.. use the intrinsic datetime functions. But for the record:-
Access / JET stores datetime values as a decimal number (forget the precise type, suspect its a double). The integer portion is the number of days since, IIRC, 31 Dec 1899. The decimal is the time component expressed as a proportion of a day.
0 is 00:00:00
0.5 is 12:00:00
0.75 is 18:00:00
A second is 1 / (24 * 60 *60) ' or 1 / ( 24 hours * 60 minutes * 60 seconds)
Its increasingly unlikely that JET will change its way of doing dates, but using the intrinsic functions means you are protected somewhat against such changes, where as using
Code:
`date () - 30`
leaves you expised. The datetime functions also provide an eadier way of manipulating and extracting temporal data
Last edited by healdem; 01-18-16 at 05:47.

Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•