Books Online?alter function [dbo].[F_START_OF_WEEK] (@DATE datetime,-- Sun = 1, Mon = 2, Tue = 3, Wed = 4-- Thu = 5, Fri = 6, Sat = 7-- Default to Sunday@WEEK_START_DAY int = 1 ) /*Find the first date on or before @DATE that matches day of week of @WEEK_START_DAY.*/returns datetimewith schemabindingasbegindeclare @START_OF_WEEK_DATE datetimedeclare @FIRST_BOW datetime-- Check for valid day of weekif @WEEK_START_DAY between 1 and 7begin-- Find first day on or after 1753/1/1 (-53690)-- matching day of week of @WEEK_START_DAY-- 1753/1/1 is earliest possible SQL Server date.select @FIRST_BOW = convert(datetime,-53690+((@WEEK_START_DAY+5)%7))-- Verify beginning of week not before 1753/1/1if @DATE >= @FIRST_BOWbeginselect @START_OF_WEEK_DATE = dateadd(dd,(datediff(dd,@FIRST_BOW,@DATE)/7)*7,@FIRST_BOW)endendreturn @START_OF_WEEK_DATEend
E 12°55'05.63"N 56°04'39.26"