Skip to content

Commit

Permalink
feat: implement dateadd macro
Browse files Browse the repository at this point in the history
  • Loading branch information
silviustanimir committed Nov 14, 2023
1 parent 8a89554 commit de7beb2
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions macros/multiple_databases/dateadd.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{%- macro dateadd(datepart, number, date_field) -%}

{%- if target.type == 'databricks' -%}
{%- if datepart == 'millisecond' -%}
timestamp_millis(unix_millis({{ date_field }}) + {{ number }})
{%- elif datepart == 'second' -%}
timestamp_seconds(unix_seconds({{ date_field }}) + {{ number }})
{%- elif datepart == 'minute' -%}
timestamp_seconds(unix_seconds({{ date_field }}) + {{ number }}*60)
{%- elif datepart == 'hour' -%}
timestamp_seconds(unix_seconds({{ date_field }}) + {{ number }}*3600)
{%- elif datepart == 'day' -%}
date_add({{ datepart }}, {{ number }})
{%- elif datepart == 'week' -%}
date_add({{ datepart }}, {{ number }}*7)
{%- endif -%}
{%- else -%}
dateadd({{ datepart }}, {{ number }}, {{ date_field }})
{%- endif -%}
{%- endmacro -%}

0 comments on commit de7beb2

Please sign in to comment.