Hi,Take a look at the following posting to get an understanding of what the first day of the week is. http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=44746As mentioned in posting, it depends on the language setting of the user running the code.For US, Sunday, day 7 is the first day of the weekFor British English, Monday, day 1 is the first day of the week.Assume you have an SP creating some sort of a time table.Following code assumes monday is the first day of the week and returns the 17th Jan for each of the following:select convert(datetime,'20050117') - (datepart(dw, convert(datetime,'20050117')) - @@datefirst)select convert(datetime,'20050118') - (datepart(dw, convert(datetime,'20050118')) - @@datefirst)select convert(datetime,'20050119') - (datepart(dw, convert(datetime,'20050119')) - @@datefirst)select convert(datetime,'20050120') - (datepart(dw, convert(datetime,'20050120')) - @@datefirst)select convert(datetime,'20050121') - (datepart(dw, convert(datetime,'20050121')) - @@datefirst)select convert(datetime,'20050122') - (datepart(dw, convert(datetime,'20050122')) - @@datefirst)select convert(datetime,'20050123') - (datepart(dw, convert(datetime,'20050123')) - @@datefirst)select convert(datetime,'20050124') - (datepart(dw, convert(datetime,'20050124')) - @@datefirst)
if Sunday is the first day of your week, then you will need somethin like:select convert(datetime,'20050124') - (@@datefirst - datepart(dw, convert(datetime,'20050124')))
Just need to substitute dates above with the your date variable.