First and Last Day of Week - SQL

Many times you might come across to a situation where you have to find the first and last day of week.

Here is the SQL script which can be used to find the first and last day of the week.

--Start of Script
DECLARE @date datetime -- Will be the date for which you want to have the Start and End of week
DECLARE @end_week datetime -- End of week
DECLARE @start_week datetime -- Start of week.
SET @date = getdate()
SET @start_week = DATEADD(d, 1 - DATEPART(dw, @date), @date)
SET @end_week = DATEADD(d,6,@start_week )

SELECT @date, @start_week, @end_week
--End of Script

Comments

Popular posts from this blog

WCF WSDL location address Issue resolved when hosted over HTTPS with basicHTTPBinding

Yellow Background issue in Word to PDF conversion

Gmail tricks - create unlimited siblings of your Gmail address