Function dateDiff()
calculates the difference of two time values (end time minus start time) and returns that value (take the integer part).
Arguments:
- End time <datetime | timestamp | string>
- Start time <datetime | timestamp | string>
- Unit <string>, valid options: day, hour, minute, second
Returns:
- Time difference <number>
Common Usage
Example: Direct calculate
uncollect ["2023-04-30 22:00:00", "2023-01-15 22:00:00"] as a
uncollect ["2023-04-28 22:00:00", "2023-01-15 23:00:00"] as b
uncollect ["day", "minute"] as c
return table(a, b, c, dateDiff(a, b, c))
| a | b | c | dateDiff(a, b, c) |
|---------------------|---------------------|--------|-------------------|
| 2023-04-30 22:00:00 | 2023-04-28 22:00:00 | day | 2 |
| 2023-01-15 22:00:00 | 2023-01-15 23:00:00 | minute | -60 |
Example: Multiply and calculate
uncollect ["2023-04-30 22:00:00", "2023-01-15 22:00:00"] as a
uncollect ["2023-04-28 22:00:00", "2023-01-15 23:00:00"] as b
uncollect ["day", "minute"] as c
with dateDiff(a, b, c) as d
return table(a, b, c, d)
| a | b | c | d |
|---------------------|---------------------|--------|---------|
| 2023-04-30 22:00:00 | 2023-04-28 22:00:00 | day | 2 |
| 2023-04-30 22:00:00 | 2023-04-28 22:00:00 | minute | 2880 |
| 2023-04-30 22:00:00 | 2023-01-15 23:00:00 | day | 104 |
| 2023-04-30 22:00:00 | 2023-01-15 23:00:00 | minute | 151140 |
| 2023-01-15 22:00:00 | 2023-04-28 22:00:00 | day | -103 |
| 2023-01-15 22:00:00 | 2023-04-28 22:00:00 | minute | -148320 |
| 2023-01-15 22:00:00 | 2023-01-15 23:00:00 | day | 0 |
| 2023-01-15 22:00:00 | 2023-01-15 23:00:00 | minute | -60 |