问题
I am running a query to bring time in 24 hr format but when i run query and it calculates time over 23:59:59, instead of going over and changing time to 00:00:00 it gives me error saying Input calculates to invalid time: 24:00:00.
FORMAT_TIME('%T',
TIME(DIV(sc.timestart, 60),
MOD(sc.timestart, 60),
0)) AS TimeFrom,
FORMAT_TIME('%k',
TIME(DIV(sc.timestart + sc.timeduration, 60),
MOD(sc.timestart + sc.timeduration, 60),
0)) AS TimeTo
Error Input calculates to invalid time: 24:00:00
Row ClassID TimeFrom timeduration Timeto_shouldBE
1 7786918 23:00:00 60
2 339893 23:00:00 30
3 4665919 23:00:00 60
4 7384955 23:00:00 60
5 6863540 23:30:00 30
6 2891444 23:30:00 30
trying to calculate it from 23:00:00 to 00:00:00 or beyond
回答1:
Below is for BigQuery Standard SQL
#standardSQL
SELECT ClassID,
TIME(TIMESTAMP_ADD(TIMESTAMP(CURRENT_DATE()), INTERVAL timestart MINUTE)) AS TimeFrom,
timeduration,
TIME(TIMESTAMP_ADD(TIMESTAMP(CURRENT_DATE()), INTERVAL timestart + timeduration MINUTE)) AS TimeTo
FROM `project.dataset.table`
回答2:
This works fine with the time
data type:
select time_add(cast('23:00:00' as time), interval 120 minute)
I would suggest that you use this structure for your expression.
来源:https://stackoverflow.com/questions/54635785/input-calculates-to-invalid-time-240000-in-big-query