//First and Last Day of Current Month in SQL Server
DECLARE @mydate DATETIME
SELECT @mydate = GETDATE()
SELECT CONVERT(VARCHAR(25),DATEADD(dd,-(DAY(@mydate)-1),@mydate),103) AS Date,
'First Day of Current Month' AS Type
UNION
SELECT CONVERT(VARCHAR(25),DATEADD(dd,-(DAY(DATEADD(mm,1,@mydate))),DATEADD(mm,1,@mydate)),103) AS Date ,
'Last Day of Current Month' AS Type
=======================================================================
==>O/P:=
Date Type
01/06/2016 | First Day of Current Month
30/06/2016 | Last Day of Current Month
DECLARE @mydate DATETIME
SELECT @mydate = GETDATE()
SELECT CONVERT(VARCHAR(25),DATEADD(dd,-(DAY(@mydate)-1),@mydate),103) AS Date,
'First Day of Current Month' AS Type
UNION
SELECT CONVERT(VARCHAR(25),DATEADD(dd,-(DAY(DATEADD(mm,1,@mydate))),DATEADD(mm,1,@mydate)),103) AS Date ,
'Last Day of Current Month' AS Type
=======================================================================
==>O/P:=
Date Type
01/06/2016 | First Day of Current Month
30/06/2016 | Last Day of Current Month
No comments:
Post a Comment