Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Date help for Dynamic Year and static Month and Day 1

Status
Not open for further replies.

dscoiho

MIS
Sep 26, 2005
51
US
I am using SQL Server 2005. I am trying to get date function where year changes each year but my month and day stay the same. I need for ex... '2008-12-01' current, next year it would be '2009-12-01'. It will always be the beginning of the static month.

Thanks in advance.
 
Code:
SELECT DATEADD(yy,  1,'20081201') -- 01 Dec 2009
SELECT DATEADD(yy, -1,'20081201') -- 01 Dec 2007
SELECT DATEADD(yy, -2,'20081201') -- 01 Dec 2006
SELECT DATEADD(yy, 30,'20081201') -- 01 Dec 2038
So, choose a basic year and then add whatever value you want to year portion :)

Borislav Borissov
VFP9 SP2, SQL Server 2000/2005.
 
Or, to return the 1st Dec of the year of any given date:

Code:
declare @d datetime
set @d = '2003-07-23'
SELECT dateadd(mm,11,DATEADD(yy, DATEDIFF(yy,0,@d), 0))


~LFCfan

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top