The given script below will give details for a given date as below.
1. First Day of the month along with the Weekday
2. Weekday of the Given date
3. Last day of the month along with the Weekday
Script:
DECLARE @date DATETIME
SELECT @date = GETDATE() --INPUT YOUR DATE HERE
SELECT CONVERT(VARCHAR(25),DATEADD(dd,-(DAY(@date)-1),@date),101) AS DateofMonth,datename(dw,CONVERT(VARCHAR(25),DATEADD(dd,-(DAY(@date)-1) ,@date),101)) as Week_Day,
'First Day of Month for Date Given' AS DayofMonth
UNION
SELECT CONVERT(VARCHAR(25),GETDATE(),101) AS DateofMonth, DAtename(dw,CONVERT(VARCHAR(25),GETDATE(),101)) as Week_Day,'Date Given' AS DayofMonth
UNION
SELECT CONVERT(VARCHAR(25),DATEADD(dd,-(DAY(DATEADD(mm,1,@date))),DATEADD(mm,1,@date)),101) ,DAtename(dw,CONVERT(VARCHAR(25),DATEADD(dd,-(DAY(DATEADD(mm,1,@date))) ,DATEADD(mm,1,@date)),101)) as Week_Day,
'Last Day of Month for Date Given'
Result:
DateofMonth Week_Day DayofMonth
01/01/2011 Saturday First Day of Month for Date Given
01/16/2011 Sunday  Date Given
01/31/2011 Monday  Last Day of Month for Date Given
Wow! Wow! Wow! THANK YOU!
                      -
                    
I announced my retirement from SQL/tech here and your comments on my blog, 
on LinkedIn, and on Facebook were overwhelming and humbling! I’m so touched 
by t...
1 year ago
 
 
 

 
 Posts
Posts
 
 
No comments:
Post a Comment