添加五个小时到时间戳字段

rbk*_*016 2 google-bigquery

我想添加几个小时,例如:5小时30分钟到时间戳字段使用bigquery.我的时间戳字段格式为'2016-05-03 21:35:03'

我怎样才能在bigquery中做到这一点?

Ell*_*ard 9

为完整起见,等效的标准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 |
+---------------------+
Run Code Online (Sandbox Code Playgroud)

文档TIMESTAMP_ADD位于:https://cloud.google.com/bigquery/sql-reference/functions-and-operators#timestamp_add


Mik*_*ant 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)
Run Code Online (Sandbox Code Playgroud)

有关详细信息,请参阅DATE_ADD

  • 这仅适用于旧版SQL - 请参阅@Ellot Brossard对标准SQL解决方案的回答 (2认同)