答案 0 :(得分:6)
date
表格中的ga_sessions
列格式为YYYYMMDD
,因此要将其解析为日期,您可以使用:
#standardSQL
SELECT PARSE_DATE('%Y%m%d', date) AS date
FROM YourTable;
例如,
#standardSQL
WITH YourTable AS (
SELECT '20170510' AS date UNION ALL
SELECT '20170508'
)
SELECT PARSE_DATE('%Y%m%d', date) AS date
FROM YourTable;
如果您想将日期更改为其他格式,可以使用FORMAT_DATE
功能,例如:
#standardSQL
WITH YourTable AS (
SELECT '20170510' AS date UNION ALL
SELECT '20170508'
)
SELECT
date,
FORMAT_DATE('%m%d%y', date) AS mmddyy_format,
FORMAT_DATE('%d-%m-%Y', date) AS dd_mm_yyyy_format
FROM (
SELECT PARSE_DATE('%Y%m%d', date) AS date
FROM YourTable
);
您可以阅读PARSE_DATE
和FORMAT_DATE
in the documentation支持的格式元素。