From 53a928af587f5a3dc1aaefecf861f89f49cc1628 Mon Sep 17 00:00:00 2001 From: Ly Nguyen Date: Wed, 8 May 2024 15:23:05 -0700 Subject: [PATCH 1/6] New to_date macro --- .../cross-database-macros.md | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/website/docs/reference/dbt-jinja-functions/cross-database-macros.md b/website/docs/reference/dbt-jinja-functions/cross-database-macros.md index e13dba0bdec..03cf73e42f2 100644 --- a/website/docs/reference/dbt-jinja-functions/cross-database-macros.md +++ b/website/docs/reference/dbt-jinja-functions/cross-database-macros.md @@ -58,6 +58,7 @@ Please make sure to take a look at the [SQL expressions section](#sql-expression - [cast\_bool\_to\_text](#cast_bool_to_text) - [safe\_cast](#safe_cast) - [Date and time functions](#date-and-time-functions) + - [date](#date) - [dateadd](#dateadd) - [datediff](#datediff) - [date\_trunc](#date_trunc) @@ -106,6 +107,7 @@ Please make sure to take a look at the [SQL expressions section](#sql-expression - [cast\_bool\_to\_text](#cast_bool_to_text) - [safe\_cast](#safe_cast) - [Date and time functions](#date-and-time-functions) + - [date](#date) - [dateadd](#dateadd) - [datediff](#datediff) - [date\_trunc](#date_trunc) @@ -176,6 +178,7 @@ Please make sure to take a look at the [SQL expressions section](#sql-expression - [safe_cast](#safe_cast) [**Date and time functions**](#date-and-time-functions) +- [date](#date) - [dateadd](#dateadd) - [datediff](#datediff) - [date_trunc](#date_trunc) @@ -884,6 +887,29 @@ For databases that support it, this macro will return `NULL` when the cast fails ## Date and time functions +### date + +**Availability**: +dbt v1.8 or later. For more information, select the version from the documentation navigation menu. + + + +__Args__: + + * `year`: an integer + * `month`: an integer + * `day`: an integer + +This macro converts an ISO 8601-formatted date string into an SQL `DATE` type. + +**Usage**: + + +**Sample output**: + + + + ### dateadd __Args__: From e7d4d8c1324cef20e41e0de71758e744be739cf0 Mon Sep 17 00:00:00 2001 From: Ly Nguyen Date: Wed, 8 May 2024 15:45:42 -0700 Subject: [PATCH 2/6] Minor nits --- .../dbt-jinja-functions/cross-database-macros.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/website/docs/reference/dbt-jinja-functions/cross-database-macros.md b/website/docs/reference/dbt-jinja-functions/cross-database-macros.md index 03cf73e42f2..dbb828d8cc2 100644 --- a/website/docs/reference/dbt-jinja-functions/cross-database-macros.md +++ b/website/docs/reference/dbt-jinja-functions/cross-database-macros.md @@ -896,11 +896,11 @@ dbt v1.8 or later. For more information, select the version from the documentati __Args__: - * `year`: an integer - * `month`: an integer - * `day`: an integer + * `year`: an integer (`YYYY`) + * `month`: an integer (`MM`) + * `day`: an integer (`DD`) -This macro converts an ISO 8601-formatted date string into an SQL `DATE` type. +This macro converts an ISO 8601-formatted date string (`YYYY-MM-DD`) into an SQL `DATE` type. **Usage**: From dd0ea6ee7b3c79dc3e7e2ec053211ba146ab8cb2 Mon Sep 17 00:00:00 2001 From: Ly Nguyen Date: Wed, 8 May 2024 15:54:03 -0700 Subject: [PATCH 3/6] Add example usage --- .../dbt-jinja-functions/cross-database-macros.md | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/website/docs/reference/dbt-jinja-functions/cross-database-macros.md b/website/docs/reference/dbt-jinja-functions/cross-database-macros.md index dbb828d8cc2..703b22774c8 100644 --- a/website/docs/reference/dbt-jinja-functions/cross-database-macros.md +++ b/website/docs/reference/dbt-jinja-functions/cross-database-macros.md @@ -896,14 +896,17 @@ dbt v1.8 or later. For more information, select the version from the documentati __Args__: - * `year`: an integer (`YYYY`) - * `month`: an integer (`MM`) - * `day`: an integer (`DD`) + * `year`: an integer + * `month`: an integer + * `day`: an integer This macro converts an ISO 8601-formatted date string (`YYYY-MM-DD`) into an SQL `DATE` type. **Usage**: +```sql +{{ dbt.to_date(2023, 10, 4) }} +``` **Sample output**: From c84d49423706994316c77b694133f3531df93c5f Mon Sep 17 00:00:00 2001 From: Ly Nguyen Date: Wed, 8 May 2024 16:04:46 -0700 Subject: [PATCH 4/6] Add sample output --- .../reference/dbt-jinja-functions/cross-database-macros.md | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/website/docs/reference/dbt-jinja-functions/cross-database-macros.md b/website/docs/reference/dbt-jinja-functions/cross-database-macros.md index 703b22774c8..a543f2f3507 100644 --- a/website/docs/reference/dbt-jinja-functions/cross-database-macros.md +++ b/website/docs/reference/dbt-jinja-functions/cross-database-macros.md @@ -900,7 +900,7 @@ __Args__: * `month`: an integer * `day`: an integer -This macro converts an ISO 8601-formatted date string (`YYYY-MM-DD`) into an SQL `DATE` type. +This macro converts the `year`, `month`, and `day` into an SQL `DATE` type. **Usage**: @@ -910,6 +910,9 @@ This macro converts an ISO 8601-formatted date string (`YYYY-MM-DD`) into an SQL **Sample output**: +```sql +2023-10-04 +``` From 4f82bdc8054fc760578314800086af4bc8b8537e Mon Sep 17 00:00:00 2001 From: Ly Nguyen Date: Wed, 8 May 2024 16:12:25 -0700 Subject: [PATCH 5/6] Nit --- .../docs/reference/dbt-jinja-functions/cross-database-macros.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/website/docs/reference/dbt-jinja-functions/cross-database-macros.md b/website/docs/reference/dbt-jinja-functions/cross-database-macros.md index a543f2f3507..ebb87a1b1ff 100644 --- a/website/docs/reference/dbt-jinja-functions/cross-database-macros.md +++ b/website/docs/reference/dbt-jinja-functions/cross-database-macros.md @@ -908,7 +908,7 @@ This macro converts the `year`, `month`, and `day` into an SQL `DATE` type. {{ dbt.to_date(2023, 10, 4) }} ``` -**Sample output**: +**Sample output (PostgreSQL)**: ```sql 2023-10-04 From cd23fdb816748e5f55915c3ee23ee400ac206007 Mon Sep 17 00:00:00 2001 From: Doug Beatty <44704949+dbeatty10@users.noreply.github.com> Date: Thu, 9 May 2024 14:23:24 -0600 Subject: [PATCH 6/6] Update code example --- .../reference/dbt-jinja-functions/cross-database-macros.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/website/docs/reference/dbt-jinja-functions/cross-database-macros.md b/website/docs/reference/dbt-jinja-functions/cross-database-macros.md index ebb87a1b1ff..0c7e93bf296 100644 --- a/website/docs/reference/dbt-jinja-functions/cross-database-macros.md +++ b/website/docs/reference/dbt-jinja-functions/cross-database-macros.md @@ -905,13 +905,13 @@ This macro converts the `year`, `month`, and `day` into an SQL `DATE` type. **Usage**: ```sql -{{ dbt.to_date(2023, 10, 4) }} +{{ dbt.date(2023, 10, 4) }} ``` **Sample output (PostgreSQL)**: ```sql -2023-10-04 +to_date('2023-10-04', 'YYYY-MM-DD') ```