Forum Documentation Showcase Pricing Learn more

Date interval math


In the reference documentation it says the “date interval type” stores a number of milliseconds and that you can do math on it.
Specifically: “Adding and subtracting Date intervals always performs absolute math, not calendar-aware math”

I thought that would be a good way to track how long people are spending doing different things in my app.

But when I try to add two date intervals together the only option is to convert the date interval into days/hours/minutes/seconds and then I can do math on those, but I can’t convert days/hours/minutes/seconds back into a date interval.

So how do I add and subtract date intervals?


To convert a value to an interval, you need a start date or an interval end date. Knowing one of the dates we find the second + - values. Having two dates you can find the interval)))