Skip to content

Instantly share code, notes, and snippets.

@infinex
Last active March 12, 2018 16:06
Show Gist options
  • Select an option

  • Save infinex/0b000604c8a1e762572c0cba9a6c77b1 to your computer and use it in GitHub Desktop.

Select an option

Save infinex/0b000604c8a1e762572c0cba9a6c77b1 to your computer and use it in GitHub Desktop.
big query date
#standard sql
SELECT "Current Month" as type,cast(TIMESTAMP_TRUNC(CURRENT_TIMESTAMP(), MONTH) as date)
UNION ALL
SELECT "Week ending",DATE_ADD(cast(TIMESTAMP_TRUNC(CURRENT_TIMESTAMP(), WEEK) as date),interval 7 DAY)
UNION ALL
SELECT "Current Month",DATE_TRUNC(CURRENT_DATE,MONTH)
UNION ALL
SELECT "First day of last Month",DATE_TRUNC(DATE_SUB(CURRENT_DATE,INTERVAL 1 MONTH),MONTH)
UNION ALL
SELECT "Last day of the currrent month",DATE_SUB(DATE_TRUNC(DATE_ADD(CURRENT_DATE(), INTERVAL 1 MONTH), MONTH), INTERVAL 1 DAY)
UNION ALL
SELECT "Last day of the previous month",DATE_SUB(DATE_TRUNC(CURRENT_DATE(), MONTH), INTERVAL 1 DAY)
UNION ALL
SELECT "Last day of the two month",DATE_SUB(DATE_TRUNC(DATE_SUB(CURRENT_DATE(), INTERVAL 1 MONTH), MONTH), INTERVAL 1 DAY)
@infinex
Copy link
Author

infinex commented Mar 12, 2018

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment