Skip to content

toInterval

Description

Returns an interval created from a numeric value and an optional time unit.

This function works with integers, decimals, 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.

toInterval(number: number, timeUnit?: timeunit): interval
(number: number).toInterval(timeUnit?: timeunit): interval

Arguments

NameTypeRequiredDescription

| number | number | true | The number to convert into an interval | | timeUnit | timeunit | false | The time unit of the value. Defaults to nano |

Example

Use case: Add numeric duration to a timestamp to compute an end time

A log contains a start_time and a numeric duration in seconds. Convert the duration into an interval and add it to the timestamp.

{
  "start_time": 1728763337,
  "duration_seconds": 50
}

Example query

create end_time from addTime(start_time, duration_seconds.toInterval('s'))
create end_time from start_time.addTime(duration_seconds.toInterval('s'))

Example output

{
  "start_time": 1728763337,
  "duration_seconds": 50,
  "end_time": 1728763387
}
Was this helpful?