SQL 查询结果中的 google-bigquery 格式日期为 mm/dd/yyyy
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/40156035/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
google-bigquery format date as mm/dd/yyyy in query results
提问by Eric Hendershott
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,
提前致谢,
回答by Mikhail Berlyant
In BigQuery Legacy SQL
在 BigQuery 旧版 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 标准 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 迁移也很有用