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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

12 month data

Status
Not open for further replies.

parsql

MIS
Nov 10, 2005
106
US
Hi all,

need help to figure out that how can i get last 12 month of data for any given date. i have start and end date.

should i do like datediff(mm, 12, getdate())
??
thanks
 
change getdate to DATEADD(dd, DATEDIFF(dd, 0, getdate())+0, 0) to strip of the time

where SomeValue >= dateadd(yy, -1, DATEADD(dd, DATEDIFF(dd, 0, getdate())+0, 0))

or

where SomeValue >= dateadd(mm, -12, DATEADD(dd, DATEDIFF(dd, 0, getdate())+0, 0))


test with this
select dateadd(yy, -1, DATEADD(dd, DATEDIFF(dd, 0, getdate())+0, 0))
select dateadd(mm, -12, DATEADD(dd, DATEDIFF(dd, 0, getdate())+0, 0))

Denis The SQL Menace
SQL blog:
Personal Blog:
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top