Sep 19, 2006 #1 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
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
Sep 19, 2006 #2 SQLDenis Programmer Oct 1, 2005 5,575 US where SomeValue >= dateadd(yy, -1, getdate()) or where SomeValue >= dateadd(mm, -12, getdate()) test with this select dateadd(yy, -1, getdate()) select dateadd(mm, -12, getdate()) Denis The SQL Menace SQL blog:http://sqlservercode.blogspot.com/ Personal Blog:http://otherthingsnow.blogspot.com/ Upvote 0 Downvote
where SomeValue >= dateadd(yy, -1, getdate()) or where SomeValue >= dateadd(mm, -12, getdate()) test with this select dateadd(yy, -1, getdate()) select dateadd(mm, -12, getdate()) Denis The SQL Menace SQL blog:http://sqlservercode.blogspot.com/ Personal Blog:http://otherthingsnow.blogspot.com/
Sep 19, 2006 #3 SQLDenis Programmer Oct 1, 2005 5,575 US 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:http://sqlservercode.blogspot.com/ Personal Blog:http://otherthingsnow.blogspot.com/ Upvote 0 Downvote
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:http://sqlservercode.blogspot.com/ Personal Blog:http://otherthingsnow.blogspot.com/