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
 SQL Server 2008 Forums
 Transact-SQL (2008)
 Date function for: One Year back from yesterday

Author  Topic 

mgreen84
Yak Posting Veteran

94 Posts

Posted - 2014-04-02 : 12:04:59
Hi can anyone assist me with this, I'm trying to Select the date one year back from yesterday.

I've tried the following but neither works, I keep getting a year of 1900


Select DATEADD(Day,DATEDIFF(Year, -1, getDate())-1,0)

sqlsaga
Yak Posting Veteran

93 Posts

Posted - 2014-04-02 : 12:38:56
see this...

SELECT DATEADD(YYYY, -1, DATEADD(d, -1, CONVERT(DATE, GETDATE())))



Visit www.sqlsaga.com for more t-sql code snippets and BI related how to articles.
Go to Top of Page

mgreen84
Yak Posting Veteran

94 Posts

Posted - 2014-04-02 : 14:49:47
Ah, Sweet! works perfectly!

quote:
Originally posted by sqlsaga

see this...

SELECT DATEADD(YYYY, -1, DATEADD(d, -1, CONVERT(DATE, GETDATE())))



Visit www.sqlsaga.com for more t-sql code snippets and BI related how to articles.

Go to Top of Page
   

- Advertisement -