Find Last Day of Previous, Current and Next Month using MSSQL

DECLARE @date DATETIME

SELECT @date = GETDATE()

SELECT CONVERT(VARCHAR(25), DATEADD(dd, – (DAY(@date)), @date), 101) AS ‘Last Day of Previous Month’

SELECT CONVERT(VARCHAR(25), DATEADD(dd, – (DAY(@date) – 1), @date), 101) AS ‘First Day of Current Month’

SELECT CONVERT(VARCHAR(25), DATEADD(dd, – (DAY(DATEADD(mm, 1, @date))), DATEADD(mm, 1, @date)), 101) AS ‘Last Day of Current Month’

SELECT CONVERT(VARCHAR(25), DATEADD(dd, – (DAY(DATEADD(mm, 1, @date)) – 1), DATEADD(mm, 1, @date)), 101) AS ‘First Day of Next Month’

SELECT DATENAME(MONTH, GETDATE()) + ‘ ‘ + DATENAME(YEAR, GETDATE())

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s