Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bigquery Custom first day of week (defaults Monday)

I am trying to extract week from date using the function

format_timestamp('%V', DATE)

but Bigquery documentation says "Monday as the first day of the week".

Is there a way where I can specify Tuesday as first day of week.

I have achieved the same in Redshift using

date_part(week, date + interval '-1 day')

Is it possible in Bigquery?

like image 448
rahulb Avatar asked Oct 15 '25 15:10

rahulb


1 Answers

Below is for BigQuery Standard SQL

You can use WEEK(WEEKDAY) as shown below

#standardSQL
SELECT FORMAT_TIMESTAMP('%V', CURRENT_TIMESTAMP()), 
EXTRACT(WEEK(SATURDAY) FROM CURRENT_TIMESTAMP())

This was introduced quite recently - https://cloud.google.com/bigquery/docs/release-notes#november_30_2017

like image 186
Mikhail Berlyant Avatar answered Oct 18 '25 20:10

Mikhail Berlyant