Firstday,Lastday,Day of week

,

Script lists 'First day of the week','Last day of the week','Last day of the month' and 'First day of the month'

/*************************************************************************************************
                                          
Purpose:	'First day of the week','Last day of the week','Last day of the month'  and 'First day of the month'  

Written by:	Anand Mohan

Tested on: 	SQL Server 7.0 and SQL Server 2000

Date modified:	

Email: 		dtvam@idia.com
Examples:

List the 'First day of the week','Last day of the week','Last day of the month'  and 'First day of the month' on valid date input

***********************************************************DECLARE @Date datetime
SET @Date = getdate()
SELECT DATEADD(dd,-(DATEPART(dw, @Date) - 1),@Date) AS 'First day of the week'
SELECT DATEADD(dd,-(DATEPART(dw, @Date) - 7),@Date) AS 'Last day of the week'
SELECT DATEADD(d, -DAY(DATEADD(m,1,@Date)),DATEADD(m,1,@Date)) AS 'Last day of the month' 
SELECT DATENAME(dw, DATEADD(dd, - DATEPART(dd, GETDATE()) + 1, GETDATE())) AS 'First day of the month'

Rate

Share

Share

Rate