From 5da3270b8787004fb1dfaa0858de122795e31240 Mon Sep 17 00:00:00 2001 From: Will Beasley Date: Tue, 3 Dec 2024 12:05:55 -0600 Subject: [PATCH] doc for sql's `datetrunc()` --- R/dates.R | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/R/dates.R b/R/dates.R index dd4ca8e..2f3c376 100644 --- a/R/dates.R +++ b/R/dates.R @@ -29,7 +29,12 @@ #' The [sql equivalent](https://docs.microsoft.com/en-us/sql/t-sql/functions/datepart-transact-sql) to `clump_month_date()` #' is `cast(convert(char(7), getdate(), 126) + '-15' as date)`. #' The [sql equivalent](https://blog.sqlauthority.com/2007/08/20/sql-server-find-monday-of-the-current-week/) to `clump_week_date()` -#' is `SELECT dateadd(wk, datediff(wk, 0, getdate()), 0)` +#' is `SELECT dateadd(week, datediff(week, 0, getdate()), 0)`. +#' Starting with SQL Server 2022, the [`datetrunc()`](https://learn.microsoft.com/en-us/sql/t-sql/functions/datetrunc-transact-sql?view=sql-server-ver16) +#' function is available. +#' Assume `DECLARE @d date = cast(getdate() as date);`, then it's +#' `SELECT dateadd(day, 14, datetrunc(month, @d))` +#' and `SELECT dateadd(day, 1, datetrunc(week, @d))`. #' #' @author Will Beasley #'