Results 1 to 4 of 4
  1. #1
    Join Date
    Sep 2008
    Posts
    150

    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.

    Appreciate your help.

  2. #2
    Join Date
    Feb 2004
    Location
    New Zealand
    Posts
    1,424
    Provided Answers: 8
    Look up

    =DateAdd('d',-30,date())
    hope this help

    See clear as mud


    StePhan McKillen
    the aim is store once, not store multiple times
    Remember... Optimize 'til you die!
    Progaming environment:
    Access based on my own environment: DAO3.6/A97/A2000/A2003/A2007/A2010
    VB based on my own environment: vb6 sp5
    ASP based on my own environment: 5.6
    VB-NET based on my own environment started 2007
    SQL-2005 based on my own environment started 2008
    MYLE
    YOUR PASSWORD IS JUST LIKE YOUR TOOTHBRUSH DON'T SHARE IT.

  3. #3
    Join Date
    Sep 2008
    Posts
    150
    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?

  4. #4
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    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.
    I'd rather be riding on the Tiger 800 or the Norton

Posting Permissions

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