Home > database >  Big Query get first day of week
Big Query get first day of week

Time:09-16

I'm working with Big Query and I need to get first day of week.

For example if date = '2022-08-26' I want to have '2022-08-22' where 22 is Monday.

Any solutions please ?

Thanks in advance.

CodePudding user response:

To achieve this you'll want to use the DATE_TRUNC function as follows:

select date_trunc(date('2022-08-26'), WEEK(MONDAY))

You can change the parameter for WEEK to be any day of the week, default is SUNDAY.

Documentation can be found here: https://cloud.google.com/bigquery/docs/reference/standard-sql/date_functions#date_trunc

  • Related