Skip to content

Commit

Permalink
Merge pull request #54 from calogica/fix/snowflake-week-start
Browse files Browse the repository at this point in the history
Fix week_start on Snowflake
  • Loading branch information
clausherther authored Jan 13, 2022
2 parents cf9b6d6 + 38d4ee7 commit 2f06e3e
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions macros/calendar_date/week_start.sql
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,12 @@ cast({{ dbt_utils.date_trunc('week', date) }} as date)
{%- endmacro %}

{%- macro snowflake__week_start(date) -%}
case
when {{ dbt_date.day_of_week(dbt_utils.date_trunc('week', date), isoweek=False) }} = 1
then {{ dbt_date.n_days_ago(
dbt_date.day_of_week(date, isoweek=False) ~ " - 1",
date
) }}
end
{#
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) -%}
Expand Down

0 comments on commit 2f06e3e

Please sign in to comment.