forked from calogica/dbt-date
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathweek_start.sql
More file actions
22 lines (19 loc) · 852 Bytes
/
Copy pathweek_start.sql
File metadata and controls
22 lines (19 loc) · 852 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
{%- macro week_start(date=None, tz=None) -%}
{%-set dt = date if date else dbt_date.today(tz) -%}
{{ adapter.dispatch('week_start', 'dbt_date') (dt) }}
{%- endmacro -%}
{%- macro default__week_start(date) -%}
cast({{ dbt_utils.date_trunc('week', date) }} as date)
{%- endmacro %}
{%- macro snowflake__week_start(date) -%}
{#
Get the day of week offset: e.g. if the date is a Sunday,
dbt_date.day_of_week returns 1, so we subtract 1 to get a 0 offset
#}
{% set off_set = dbt_date.day_of_week(date, isoweek=False) ~ " - 1" %}
cast({{ dbt_utils.dateadd("day", "-1 * (" ~ off_set ~ ")", date) }} as date)
{%- endmacro %}
{%- macro postgres__week_start(date) -%}
-- Sunday as week start date
cast({{ dbt_utils.dateadd('day', -1, dbt_utils.date_trunc('week', dbt_utils.dateadd('day', 1, date))) }} as date)
{%- endmacro %}