Script lists 'First day of the week','Last day of the week','Last day of the month' and 'First day of the month'
2007-10-02 (first published: 2002-06-20)
15,459 reads
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'