Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

google-bigquery format date as mm/dd/yyyy in query results

I am using Bigquery SQL to generate a report. The standard Bigquery date format is yyyy-mm-dd, but I want it to be formatted as mm/dd/yyyy.

Is there a way via Bigquery SQL to convert the date format on SELECT?

Thanks in advance,

like image 850
Eric Hendershott Avatar asked Oct 20 '16 13:10

Eric Hendershott


People also ask

What is the difference between datetime and timestamp in BigQuery?

Datetime type: comprises both calendar date and time. It does not store time zone information: YYYY-MM-DD HH:MM:SS (e.g. ). Timestamp type: comprises date, time, and time zone information.


1 Answers

In BigQuery Legacy SQL

SELECT 
  STRFTIME_UTC_USEC("2016-10-20", "%m/%d/%Y"),   
  STRFTIME_UTC_USEC(CURRENT_DATE(), "%m/%d/%Y")  

In BigQuery Standard SQL (see Enabling Standard SQL)

SELECT 
  FORMAT_DATE("%m/%d/%Y", DATE "2016-10-20"), 
  FORMAT_DATE("%m/%d/%Y", CURRENT_DATE())

Also useful Migrating from legacy SQL

like image 172
Mikhail Berlyant Avatar answered Sep 30 '22 23:09

Mikhail Berlyant