none
How to indicate day(s) ago in SQL for Access RRS feed

  • Question

  • I am not sure where to post this but I am trying to write SQL for Access so that I can query data created a day ago using today's date. In other words, data created a day ago from today's date.

    Any directions will be appreciated!

     

    Thank everyone.

    Friday, December 9, 2011 4:03 PM

Answers

All replies

  • Try using the DateAdd() function to get all dates from Today - 1, see below example:

     

    SELECT * FROM tblCustomers
    WHERE [MyDate] = DateAdd("d",-1,Date());
    

    Hope this helps,


    Daniel van den Berg | Washington, USA | "Anticipate the difficult by managing the easy"
    Friday, December 9, 2011 4:30 PM
    Moderator
  • Try using the DateAdd() function to get all dates from Today - 1, see below example:

     

     

    SELECT * FROM tblCustomers
    WHERE [MyDate] = DateAdd("d",-1,Date());
    

     

    Hope this helps,


    Daniel van den Berg | Washington, USA | "Anticipate the difficult by managing the easy"


    Thank you so much for your help, time and patience!

    Your example is what I was looking for but lets say I want to say 1 day after, how will I do that?

     

    Thanks again!

    Friday, December 9, 2011 4:39 PM
  • Then it would be something like this, instead of -1 it wil be 1:

     

    SELECT * FROM tblCustomers
    WHERE [MyDate] = DateAdd("d",1,Date());
    

    See for more info on the DateAdd function in below thread:

    http://office.microsoft.com/en-us/access-help/dateadd-function-HA001228810.aspx

     

    Hope this helps,


    Daniel van den Berg | Washington, USA | "Anticipate the difficult by managing the easy"
    • Marked as answer by Synthologic Friday, December 9, 2011 4:45 PM
    Friday, December 9, 2011 4:44 PM
    Moderator
  • Then it would be something like this, instead of -1 it wil be 1:

     

     

    SELECT * FROM tblCustomers
    WHERE [MyDate] = DateAdd("d",1,Date());
    

     

    See for more info on the DateAdd function in below thread:

    http://office.microsoft.com/en-us/access-help/dateadd-function-HA001228810.aspx

     

    Hope this helps,


    Daniel van den Berg | Washington, USA | "Anticipate the difficult by managing the easy"

    Thanks again! Have a Great weekend.
    Friday, December 9, 2011 4:45 PM
  • You are welcome, have a great weekend too!

    Merry Christmas! :)

     


    Daniel van den Berg | Washington, USA | "Anticipate the difficult by managing the easy"
    Friday, December 9, 2011 4:49 PM
    Moderator