toInterval - Interpret numbers as intervals
The toInterval
function will take a given number, and a time unit, and convert it to an interval. This is very useful when we're attempting to perform some calculations on a date, but we do not have our fields in the correct types.
toInterval
works with both integer and decimal values. It also works with positive and negative values.
Syntax
Like many functions in DataPrime, toInterval
supports two notations, function and method notation. These interchangeable forms allow flexibility in how you structure expressions.
Arguments
Name | Type | Required | Description |
---|---|---|---|
number | number | true | The number to be converted to an interval |
timeUnit | timeunit | false | The time unit for the number. Defaults to nano |
Example - Add numeric duration to a timestamp to compute end time.
Consider the following document:
If we want to calculate end_time
, we can first use toInterval
to convert the duration_seconds
field into an actual interval, before we add it to the start_time
:
This results in the following document:
Theme
Light