Email: Password:       Forgot Password 
    .netCodeSG
A Saarsha Group Online Community for dot net codes group like C#, Asp.NET, VB.NET, Sharepoint, JavaScript, JQuery, Ajax, SQL, WCF, WPF.
 
TECHNOLOGIES:
 

SQL Server Know First Last Date and their week name and Total Days in Current Month

Article:
Viewed:  426 
Posted On:  4/1/2016 6:47:39 PM 
How we can Know First Last Date & their week name and Total Days in Current Month ? 

 

To know current day, last day & their week name and total days in current month in SQL Server use below SQL Server statement.

1.png

Image 1.

 

DECLARE @MONTH INT=3; -- Here you can set current month or get from getDate()
DECLARE @YEAR INT=2016-- Here you can set current year or get from getDate()
DECLARE @FIRSTDATE DATE;
DECLARE @LASTDATE DATE;
DECLARE @TOTALDAYS INT
 
SET @LASTDATE=(SELECT DATEADD(DAY,-1,DATEADD(MONTH,@MONTH,DATEADD(YEAR,@YEAR-1900,0))))
SET @FIRSTDATE=(SELECT DATEADD(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]

  Comment:
         HOME   |   Submit Article   |   Contact Us   |   About Us   |   Terms & Condition   |   Advertise With us