diff --git a/.changes/unreleased/Features-20240501-091604.yaml b/.changes/unreleased/Features-20240501-091604.yaml new file mode 100644 index 00000000..fb934881 --- /dev/null +++ b/.changes/unreleased/Features-20240501-091604.yaml @@ -0,0 +1,6 @@ +kind: Features +body: Cross-database `date` macro +time: 2024-05-01T09:16:04.909686-06:00 +custom: + Author: dbeatty10 + Issue: https://github.com/dbt-labs/dbt-core/issues/8831 diff --git a/dbt/include/global_project/macros/utils/date.sql b/dbt/include/global_project/macros/utils/date.sql new file mode 100644 index 00000000..d41b4438 --- /dev/null +++ b/dbt/include/global_project/macros/utils/date.sql @@ -0,0 +1,10 @@ +{% macro date(year, month, day) %} + {{ return(adapter.dispatch('date', 'dbt') (year, month, day)) }} +{% endmacro %} + + +{% macro default__date(year, month, day) -%} + {%- set dt = modules.datetime.date(year, month, day) -%} + {%- set iso_8601_formatted_date = dt.strftime('%Y-%m-%d') -%} + to_date('{{ iso_8601_formatted_date }}', 'YYYY-MM-DD') +{%- endmacro %}