Hi

Get First and Last Day of Current Month

If you want to get First and last day of current month we need to use DATEADD function and write the query like this


SELECT CONVERT(VARCHAR(10),DATEADD(dd,-(DAY(GETDATE())-1),GETDATE()),103) AS [Date],
'First Day of Current Month' AS [Type]
UNION
SELECT CONVERT(VARCHAR(10),GETDATE(),103) AS Date_Value, 'Today' AS [Type]
UNION
SELECT CONVERT(VARCHAR(10),DATEADD(dd,-(DAY(DATEADD(mm,1,GETDATE()))),DATEADD(mm,1,GETDATE())),103) AS [Date],
'Last Day of Current Month' AS [Type]
Output:

Date
Type
1/10/2012
First Day of Current Month
30/10/2012
Today
31/10/2012
Last Day of Current Month

Previous
Next Post »