September 9, 2011 at 11:15 am
Hello All
I am using this sql script
(SELECT CONVERT(VARCHAR(10) ,DATEADD(DAY,-DATEPART(DAY,GETDATE()),GETDATE()),120))
and Output of these script is "2011-08-31"
But I want Output "2011-07-31"
Anyone can modify this script and can i get output"2011-07-31"
Basically i want a output based on previous to previous month(means 2 month difference).
Like next month is October then I want ouput August.
Thanks
September 9, 2011 at 11:21 am
Does this Help, this shows the First of the previous month and the Last day from 2 months ago:SELECT DATEADD(MONTH, DATEDIFF(MONTH, 0, CURRENT_TIMESTAMP) - 1, 0),
DATEADD(MONTH, DATEDIFF(MONTH, 0, CURRENT_TIMESTAMP) - 1, 0) - 1
September 9, 2011 at 11:28 am
🙂
Thanks
IT's Work
Thanks
September 9, 2011 at 1:11 pm
Here is a post from Lynn with some common datetime routines. http://www.sqlservercentral.com/blogs/lynnpettis/archive/2009/3/25/some-common-date-routines.aspx Very good resource.
_______________________________________________________________
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 4 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply