I want to add few hours eg: 5hours 30 mins to timestamp field using bigquery. My timestamp field is in the format - '2016-05-03 21:35:03'
How can i do this in bigquery?
For completeness, the equivalent standard SQL query (uncheck "Use Legacy SQL" under "Show Options") would be:
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 |
+---------------------+
Documentation for TIMESTAMP_ADD
is here: https://cloud.google.com/bigquery/sql-reference/functions-and-operators#timestamp_add
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)
See DATE_ADD for more details
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With