We help IT Professionals succeed at work.

Is there a way to get the number of "days ago" from a date value in MS Access?

307 Views
Last Modified: 2012-06-21
I'm sure I can do this in C# code, but I wanted to know if it was possible in an access query.

Example.... This is what my table looks like....

Date            NumberOfSales
4-26-2011            40
4-27-2011            45
4-28-2011            30      
4-29-2011            28

This is what I want the query to return....

Date            NumberOfSales            DaysAgo
4-26-2011            40                  3                  
4-27-2011            45                  2
4-28-2011            30                  1      
4-29-2011            28                  0      

Addtional info. My Date column is a text type, so I may need to do some type conversion on the query in order to calculate. I'm not sure if thats possible either.
Comment
Watch Question

Commented:
DateDiff()

Ss

Commented:
I mean datediff between today, and the date in question.

Ss
CERTIFIED EXPERT
Most Valuable Expert 2015
Distinguished Expert 2018
Commented:
Unlock this solution and get a sample of our free trial.
(No credit card required)
UNLOCK SOLUTION
silentthread2kSenior Software Engineer

Author

Commented:
SELECT DateDiff("d",CDate([Date]),Date()) AS DaysAgo
FROM MyTable
Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a sample view!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.