Skip to content

Commit 5f24102

Browse files
authored
Merge pull request #6 from calogica/feature/add-dynamic-date-support-to-get_base_dates
Update base date logic to allow to dynamic date ranges
2 parents 714a51b + 688e73e commit 5f24102

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

macros/get_base_dates.sql

+15-4
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,26 @@
1-
{% macro get_base_dates(start_date, end_date) %}
1+
{% macro get_base_dates(start_date=None, end_date=None, n_dateparts=None, datepart=None) %}
22
with date_spine as
33
(
4+
{% if start_date and end_date %}
5+
{%- set start_date="cast('" ~ start_date ~ "' as datetime)" -%}
6+
{%- set end_date="cast('" ~ end_date ~ "' as datetime)" -%}
7+
8+
{% elif n_dateparts and datepart %}
9+
10+
{%- set start_date = dbt_utils.dateadd(datepart, -1 * n_dateparts, dbt_date.today()) -%}
11+
{%- set end_date = dbt_date.tomorrow() -%}
12+
{% endif %}
13+
414
{{ dbt_utils.date_spine(
515
datepart="day",
6-
start_date="cast('" ~ start_date ~ "' as datetime)",
7-
end_date="cast('" ~ end_date ~ "' as datetime)",
16+
start_date=start_date,
17+
end_date=end_date,
818
)
919
}}
20+
1021
)
1122
select
12-
d.date_day
23+
date(d.date_day) as date_day
1324
from
1425
date_spine d
1526
{% endmacro %}

0 commit comments

Comments
 (0)