From 9bc0b2a9d80f831e818b819221d0f8b0de7ac201 Mon Sep 17 00:00:00 2001 From: Matt Usher Date: Tue, 15 Dec 2020 23:36:35 -0800 Subject: [PATCH] Bug fix for date_trunc(week, expression) to move the timestamp to 00:00:00 --- SQL/Extension/functions/microsoft.date_trunc.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SQL/Extension/functions/microsoft.date_trunc.sql b/SQL/Extension/functions/microsoft.date_trunc.sql index 859c83e..fee1b63 100644 --- a/SQL/Extension/functions/microsoft.date_trunc.sql +++ b/SQL/Extension/functions/microsoft.date_trunc.sql @@ -51,7 +51,7 @@ BEGIN WHEN @unit = 'NANOSECOND' THEN DATEADD(NANOSECOND, DATEDIFF(NANOSECOND, 0, @expression), 0) -- Week - WHEN @unit = 'W' OR @unit = 'WEEK' THEN DATEADD(DAY, -(DATEPART(WEEKDAY, @expression) - 1), @expression) + WHEN @unit = 'W' OR @unit = 'WEEK' THEN DATEADD(DAY, -(DATEPART(WEEKDAY, @expression) - 1), DATEADD(DAY, DATEDIFF(DAY, 0, @expression), 0) ) -- Quarter WHEN @unit = 'QUARTER' THEN microsoft.FirstDayOfQuarter(@expression)