1

Closed

Bug in GetStartOfWeek

description

There appears to be an error in the calculations in the GetStartOfWeek function.

If you run the following:
set datefirst 1
select datetimeutil.udf_getstartofweek('1/12/2014')
It will return 1/13/2014. How can the first day of the week that contains January 12th be January 13th?
Closed Jan 13, 2015 at 6:06 PM by adss
You are right. There was an issue.

To fix it either download the latest version or just change the following line in UDF [DateTimeUtil].[UDF_GetStartOfWeek]:

Old:
DATEADD(WEEK, DATEDIFF(WEEK, @FirstOfWeekday, @ReferenceDate), @FirstOfWeekday)

New:
DATEADD(WEEK, DATEDIFF(DAY, @FirstOfWeekday, @ReferenceDate) / 7, @FirstOfWeekday)

comments