Benoit Gramond
Benoit Gramond

Reputation: 89

Google Cloud SQL date format

I need to create a view with a date column. the innitial format is YYYY-MM-DD, I need DD/MM/YYYY in the view. I tried with DATEFORMAT function but my shell returns that this function does not exist. I managed it with the following function but it is quite long, is there another way to reach this?

concat(
case when day(O.order_date) < 10 
then concat(0,day(O.order_date)) 
else day(O.order_date) end, "/", 
case when month(O.order_date) < 10 
then concat(0,month(O.order_date)) 
else month(O.order_date) end, "/", year(O.order_date)) as 'Date (Au format JJ/MM/AAAA)'

Upvotes: 0

Views: 1275

Answers (1)

alp
alp

Reputation: 712

I believe the function you need is DATE_FORMAT() for MySQL, FORMAT_DATE() for BigQuery, or TO_CHAR() for PostgreSQL.

Upvotes: 1

Related Questions