Login | Register   
RSS Feed
Download our iPhone app
Browse DevX
Sign up for e-mail newsletters from DevX

By submitting your information, you agree that devx.com may send you DevX offers via email, phone and text message, as well as email offers about other products and services that DevX believes may be of interest to you. DevX will process your information in accordance with the Quinstreet Privacy Policy.

Tip of the Day
Language: SQL Server
Expertise: Beginner
May 23, 2000



Application Security Testing: An Integral Part of DevOps

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
DevX Pro
Comment and Contribute






(Maximum characters: 1200). You have 1200 characters left.



We have made updates to our Privacy Policy to reflect the implementation of the General Data Protection Regulation.
Thanks for your registration, follow us on our social networks to keep up-to-date