Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 how to find back date

Author  Topic 

qutesanju
Posting Yak Master

193 Posts

Posted - 2010-07-01 : 03:46:01
i have to find some back dates
e.g if given date 2010-07-01
how can i find date 2009-01-01(this should be year-2 and it's start Jan 01)

e.g from select dateadd(year,-2,getdate()) -->output is 2008-07-01 02:40:08.123

but i wish to find 2009-01-01

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2010-07-01 : 04:50:07

select dateadd(year,datediff(year,0,'20100701')-1,0)


Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

qutesanju
Posting Yak Master

193 Posts

Posted - 2010-07-01 : 08:50:12
thanks Madhivanan!!!
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2010-07-01 : 10:35:42
quote:
Originally posted by qutesanju

thanks Madhivanan!!!


You are welcome

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -