Getting number of time intervals between two dates

#1

I have a start, end dates and an interval (“DAY”, “HOUR”, …).

I would like to know if there is a function that returns the number of time intervals that I would get if I perform an eval Metric with this spec with actually evaluating a metric.

Thanks

0 Likes

#2

DateTime.dateDiff(start, end, ‘INTERVAL’)

1 Like

#3

Is there a function that returns the list of timestamps based on the same input parameters?

0 Likes

#4

I didn’t find anything that exists, but you could implement a small bit of code very easily:

function timesBetween(start, end, interval) {
 var dates = [];
 for(var i = 1; i <= DateTime.dateDiff(start, end, interval); i++) {
    dates.push(start.plusIntervals(interval, i)) ; 
 }
return dates;
}

and can be called like:
timesBetween(DateTime.deserialize("2017-01-01T00:00:00Z"), DateTime.deserialize("2017-02-01T00:00:00Z"), "HOUR")

0 Likes