Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bigquery Standard SQL Date to First Day of Month

How do you convert a date in YYYY-MM-DD format to the first day of the month in BigQuery Standard SQL?

like image 357
ericbrownaustin Avatar asked Oct 27 '25 10:10

ericbrownaustin


1 Answers

Use DATE_TRUNC:

#standardSQL
SELECT DATE_TRUNC('2017-02-17', MONTH);

Or, for a more interesting example where the input is strings in the format of YYYY-MM-DD:

#standardSQL
SELECT DATE_TRUNC(CAST(s AS DATE), MONTH)
FROM (
  SELECT '2017-02-17' AS s UNION ALL
  SELECT '2017-02-14' AS s
);
like image 191
Elliott Brossard Avatar answered Oct 29 '25 09:10

Elliott Brossard



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!