SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 Calculate date back to previous year
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

HenryFulmer
Yak Posting Veteran

USA
98 Posts

Posted - 06/08/2012 :  11:37:39  Show Profile  Reply with Quote
How can I calculate the date of September 30th of the previous year?
I have a query by which I return sales records and I would like to always retrieve all records that date back until September 30th of the year before.

nigelrivett
Flowing Fount of Yak Knowledge

United Kingdom
3328 Posts

Posted - 06/08/2012 :  11:40:14  Show Profile  Visit nigelrivett's Homepage  Reply with Quote
dateadd (yy,-1,convert(varchar(4),getdate(),112)+'0901'))

==========================================
Cursors are useful if you don't know sql.
SSIS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

India
47023 Posts

Posted - 06/08/2012 :  12:10:59  Show Profile  Reply with Quote
quote:
Originally posted by HenryFulmer

How can I calculate the date of September 30th of the previous year?
I have a query by which I return sales records and I would like to always retrieve all records that date back until September 30th of the year before.


DATEADD(yy,DATEDIFF(yy,0,GETDATE()),'19000930')

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

Lamprey
Flowing Fount of Yak Knowledge

3821 Posts

Posted - 06/08/2012 :  12:36:02  Show Profile  Reply with Quote
One more way for fun:
SELECT DATEADD(YEAR,YEAR(SYSDATETIME()) - 1901, '19000930')
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.03 seconds. Powered By: Snitz Forums 2000