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

Posted on 2011-04-29
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.
Question by:silentthread2k
    LVL 9

    Expert Comment


    LVL 9

    Expert Comment

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

    LVL 48

    Accepted Solution

    That would be something like:

    DaysAgo: DateDiff("d",CDate([Date]),Date())


    Author Closing Comment

    SELECT DateDiff("d",CDate([Date]),Date()) AS DaysAgo
    FROM MyTable

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    Introduction The Visual Basic for Applications (VBA) language is at the heart of every application that you write. It is your key to taking Access beyond the world of wizards into a world where anything is possible. This article introduces you to…
    It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
    With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…
    Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

    758 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    11 Experts available now in Live!

    Get 1:1 Help Now