09 Apr 20 · npack · #Bigquery ·   Bookmark   ×

How to find FIRST_DAY, LAST_DAY of current month, next month, previous month in Google Bigquery

Using #Standard SQL

First day of the current month:

SELECT DATE_TRUNC(CURRENT_DATE(), MONTH)

Last day of the current month (first day next month minus 1):

SELECT DATE_SUB(DATE_TRUNC(DATE_ADD(CURRENT_DATE(), INTERVAL 1 MONTH), MONTH),
INTERVAL 1 DAY)

Last day of the previous month (first day current minus 1):

SELECT DATE_SUB(DATE_TRUNC(CURRENT_DATE(), MONTH), INTERVAL 1 DAY)

First day of the next month:

SELECT DATE_TRUNC(DATE_ADD(CURRENT_DATE(), INTERVAL 1 MONTH), MONTH)

npack

posted on 09 Apr 20

Enjoy great content like this and a lot more !

Signup for a free account to write a post / comment / upvote posts. Its simple and takes less than 5 seconds