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



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
--kamelgazzah@gmail.com
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"
end


go
--Examples

exec usp_first_day_and_last_day_of_week 2015,42

     

Further Readings:

Responses

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