.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Sandeep Singh
Melody Anderson
Eminent IT

Home >> Code Snippets >> SQL Query >> Post New Resource Bookmark and Share   

 Subscribe to Code Snippets

First and last day of a given week

Posted By:Kemal AL GAZZAH       Posted Date: October 12, 2015    Points: 25    Category: SQL Query    URL: http://www.dotnetspark.com  

This script calculates the first and last day of a given week using sql server

create procedure usp_first_and_last_day_of_week(@y as int,@w as int)
as begin
--Kamel Gazzah
declare @fd as datetime
set @fd='01/01/'+convert(varchar(4),@y)
select @w "week",dateadd(day,8+7*(@w-2)-datepart(weekday,@fd),@fd)"first day",dateadd(day,14+7*(@w-2)-datepart(weekday,@fd),@fd)"last day"


exec usp_first_day_and_last_day_of_week 2015,42


Further Readings:


No response found. Be the first to respond this post

Post Comment

You must Sign In To post reply
Find More code samples in C#, ASP.Net, Vb.Net and more Here

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend