在BigQuery中格式化日期 [英] Formatting a Date in BigQuery
本文介绍了在BigQuery中格式化日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在查询365天的Google Analytics(分析)数据,并将数据导出为:
I am querying 365 days worth of Google Analytics data and the data is exported as:
20170726
我想要的是以某种形式解析的
What I want is it parsed in some form:
2017-07-26
07/26/2017
07/26/2017
我相信我应该使用FORMAT_DATETIME子句/方法来完成此任务,并且具有这样的功能:
I believe I should be using the FORMAT_DATETIME clause/method to be using accomplishing this, and am have it like this:
SELECT
FORMAT_DATETIME(%m/%d/%Y, date)
日期为Google Analytics(分析)中的字段.
date being the field in Google Analytics.
推荐答案
下面是用于BigQuery标准SQL,并假定您的日期字段为STRING类型
Below is for BigQuery Standard SQL and assumes your date field is of STRING type
#standardSQL
WITH `project.dataset.table` AS (
SELECT '20170726' date
)
SELECT
FORMAT_DATE('%m/%d/%Y', PARSE_DATE('%Y%m%d', date)) AS `date_string_formatted_as_MM_DD_YYYY`,
FORMAT_DATE('%Y-%m-%d', PARSE_DATE('%Y%m%d', date)) AS `date_string_formatted_as_YYYY_MM_DD`
FROM `project.dataset.table`
有结果
Row date_string_formatted_as_MM_DD_YYYY date_string_formatted_as_YYYY_MM_DD
1 07/26/2017 2017-07-26
这篇关于在BigQuery中格式化日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文