google-bigquery格式日期为查询结果中的mm / dd / yyyy

时间:2022-12-29 15:48:05

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.

我正在使用Bigquery SQL生成报告。标准Bigquery日期格式是yyyy-mm-dd,但我希望它格式化为mm / dd / yyyy。

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

有没有办法通过Bigquery SQL在SELECT上转换日期格式?

Thanks in advance,

提前致谢,

1 个解决方案

#1


14  

In BigQuery Legacy SQL

在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)

在BigQuery Standard SQL中(请参阅启用标准SQL)

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

Also useful Migrating from legacy SQL

也很有用从旧版SQL迁移

#1


14  

In BigQuery Legacy SQL

在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)

在BigQuery Standard SQL中(请参阅启用标准SQL)

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

Also useful Migrating from legacy SQL

也很有用从旧版SQL迁移