To know current day, last day, and the week name and total days inthe current month in SQL Server use the below SQL Server statement.
- DECLARE @MONTH INT=3;
- DECLARE @YEAR INT=2016;
- DECLARE @FIRSTDATE DATE;
- DECLARE @LASTDATE DATE;
- DECLARE @TOTALDAYS INT
- SET @LASTDATE=(SELECTDATEADD(DAY,-1,DATEADD(MONTH,@MONTH,DATEADD(YEAR,@YEAR-1900,0))))
- SET @FIRSTDATE=(SELECTDATEADD(MONTH,@MONTH-1,DATEADD(YEAR,@YEAR-1900,0)))
- SET @TOTALDAYS=(DATEDIFF(D,@FIRSTDATE,@LASTDATE))+1
- SELECT @FIRSTDATE AS [FIRST DATE OF MONTH],
- DATENAME(DW,@FIRSTDATE)AS [FIRST DATE OF MONTH WEEK NAME] ,
- @LASTDATE AS [LAST DATE OF MONTH],
- DATENAME(DW,@LASTDATE)AS[LAST DATE OF MONTH WEEK NAME],
- @TOTALDAYS AS [TOTAL DAYS IN MONTH]