October 28, 2013 at 10:13 am
I am trying to use Convert and Date function and get the following dates:
Date from Oct 01,2013 thru Oct 31,2013
Dates from Sept 01,2013 thru Sept 30,2013.
Date for last year from Oct 01 ,2012 thru Oct 31,2012
I am able to get the Current month using the following :
Select Convert(VARCHAR(50), DATEADD(dd,-(DAY(getdate())-1),getdate()),101)
Select CONVERT(VARCHAR(50), DATEADD(dd,-(DAY(DATEADD(mm,1,getdate()))),DATEADD(mm,1,getdate())),101)
Kindly advise Previous month(Sept 2013) and Previous year for current month(Oct 2012)
October 28, 2013 at 10:16 am
Take a look at this post from Lynn. It has a lot of excellent datetime functions.
http://www.sqlservercentral.com/blogs/lynnpettis/2009/03/25/some-common-date-routines/%5B/url%5D
_______________________________________________________________
Need help? Help us help you.
Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.
Need to split a string? Try Jeff Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.
Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/
Viewing 2 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic. Login to reply