Year-Ago-Today Date Function

Year-Ago-Today Date Function

In Access, I can get the date that was this day of this week a year ago (i.e., if today is Monday, 5/15/00, a year ago was Monday, 5/17/99) by using this function in VBA:


Is there a way to do this in SQL?

This can be done in SQL using the DATEADD function also. You can use ww or wk to specify weeks. Here’s a SQL string that returns today’s date and this day of the week a year ago:

select datename(dw, getdate()) + " "  + cast(getdate() as varchar) as'Today', datename(dw,dateadd(ww, -52, getdate())) +  " " +     cast(dateadd(ww, -52, getdate()) as varchar) as 'A Year Ago'

Assuming today is 5/18/00 returns (abridged format):

    Thursday May 18 2000 3:53PM
    A Year Ago
    Thursday May 20 1999 3:53PM
See also  The Importance of Red Teaming in Modern Cyber Defense Strategies

About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.

About Our Journalist