我想添加几个小时,例如:使用bigquery在5小时30分钟到时间戳字段。我的时间戳字段的格式为 - ' 2016-05-03 21:35:03'
我怎么能在bigquery中这样做?
答案 0 :(得分:9)
为了完整性,等效standard SQL查询(取消选中"使用旧版SQL""显示选项")将是:
WITH T AS (
SELECT ts
FROM UNNEST([CURRENT_TIMESTAMP(),
TIMESTAMP("2016-05-03 21:35:03")]) AS ts)
SELECT TIMESTAMP_ADD(ts, INTERVAL 330 MINUTE) AS ts_plus_530
FROM T;
+---------------------+
| ts_plus_530 |
+---------------------+
| 2016-08-09 04:18:05 |
| 2016-05-04 03:05:03 |
+---------------------+
TIMESTAMP_ADD
的文档位于:https://cloud.google.com/bigquery/sql-reference/functions-and-operators#timestamp_add
答案 1 :(得分:5)
SELECT
ts,
DATE_ADD(ts, 330, "MINUTE") AS ts_plus_530
FROM
(SELECT CURRENT_TIMESTAMP() AS ts),
(SELECT TIMESTAMP("2016-05-03 21:35:03") AS ts)
有关详细信息,请参阅DATE_ADD