Get First and Last Day of Previous Month
If you want to get First and last day of previous month we need to use DATEADD function and write the query like this
SELECT CONVERT(VARCHAR(10),DATEADD(dd,-(DAY(DATEADD(mm,-1,GETDATE()))-1),DATEADD(mm,-1,GETDATE())),103) AS [Date],
'First Day of Previous Month' AS [Type]
UNION
SELECT CONVERT(VARCHAR(10),DATEADD(dd,-(DAY(GETDATE())),GETDATE()),103) AS [Date],
'Last Day of Previous Month' AS [Type]
|
Output:
Date
|
Type
|
1/9/2012
|
First Day of Previous Month
|
30/09/2012
|
Last Day of Previous Month
|
Sign up here with your email
ConversionConversion EmoticonEmoticon