Skip to content

Instantly share code, notes, and snippets.

View richardsalt's full-sized avatar
🎯
Focusing

Richard Salt richardsalt

🎯
Focusing
View GitHub Profile
@richardsalt
richardsalt / bq_date_dimension.sql
Created March 27, 2020 15:32
Generate Date Dimension Table for BigQuery
--Generate Date Dimension Table for BigQuery - adjust date range as required
--this is a modified version of ewhauser/date_dim.sql gist
SELECT
d as id,
FORMAT_DATE('%Y-%m', d) as yearMonth,
FORMAT_DATE('%F', d) as yearMonthDay,
EXTRACT(YEAR FROM d) AS year,
EXTRACT(MONTH FROM d) AS month,
FORMAT_DATE('%m', d) as monthPadded,
EXTRACT(DAY FROM d) as day,
@richardsalt
richardsalt / date_dim.sql
Created March 24, 2020 10:20 — forked from ewhauser/date_dim.sql
Generate Date Dimension Table for BigQuery
SELECT
FORMAT_DATE('%F', d) as id,
d AS full_date,
EXTRACT(YEAR FROM d) AS year,
EXTRACT(WEEK FROM d) AS year_week,
EXTRACT(DAY FROM d) AS year_day,
EXTRACT(YEAR FROM d) AS fiscal_year,
FORMAT_DATE('%Q', d) as fiscal_qtr,
EXTRACT(MONTH FROM d) AS month,
FORMAT_DATE('%B', d) as month_name,