MS SQL

Last day of Next Month? First Day of Next Month? Last Day of Previous Month? First Day of Previous Month? First Day of Current Month? Last Day of Current Month?

Hi, In this article we can see how we can get the Last day of Next Month? First Day of Next Month? Last Day of Previous Month? First Day of Previous Month? First Day of Current Month? Last Day of Current Month?

We have any way to pull the data based on using the build-in function and how you think and writing the query. 🙂

Here i am sharing the query to pull the required date

--Last day of Pervious Month
SELECT DATEADD(d,-1, DATEADD(mm, DATEDIFF(mm,0, GETDATE()),0)) as [Last day of Pervious Month] UNION ALL
SELECT DATEADD(DD,- DAY(GETDATE()),GETDATE())

--First day of Previous  Month
SELECT DATEADD(mm,-1, DATEADD(mm, DATEDIFF(mm,0, GETDATE()),0)) AS [First day of Previous  Month] UNION ALL
SELECT DATEADD(DD,-22, DATEADD(mm,-1,GETDATE()))

-- First Day of next Month
SELECT DATEADD(mm,1, DATEADD(mm, DATEDIFF(mm,0, GETDATE()),0)) AS [First Day of Next Month] UNION ALL
SELECT DATEADD(DD,- ( DAY(GETDATE()- 1 )), DATEADD(mm,1,GETDATE()))

-- Last day of Next Month
SELECT CONVERT(DATETIME,EOMONTH( DATEADD(mm,1,GETDATE()))) [Last Day of Next Month]

-- First Day of Current Month
SELECT  DATEADD(mm,DATEDIFF(mm,0, GETDATE()),0) as [First Day of Current Month]
UNION ALL
SELECT GETDATE()-DAY(GETDATE()) + 1 as [First Day of Current Month]

--Last day of Current Month
SELECT CONVERT(DATETIME,EOMONTH(GETDATE())) As [Last day of Current Month]
UNION ALL --OR
SELECT DATEADD(DD,-1, DATEADD(DD, -22, DATEADD(MM,1, GETDATE())))  

Leave a Reply

Prabhakaran Jayaraman