Skip to main content

addTime

Description

Returns a new timestamp by adding an interval to an existing timestamp.

Both timestamp and interval are first-class types in DataPrime, so ensure that the correct types are passed.

note

Negative intervals are supported and act as subtraction. For example, adding -1h to a timestamp subtracts one hour.

Syntax

Like many functions in DataPrime, addTime supports two notations, function and method. These interchangeable forms allow flexibility in how you structure expressions.

addTime(t: timestamp, i: interval): timestamp

Arguments

NameTypeRequiredDescription
ttimestamptrueThe base timestamp to modify
iintervaltrueThe interval to add (or subtract, if negative)

Example

Use case: Compute an event’s end time from its start time and duration

A log contains a start_timestamp field and a duration field in seconds. Convert the duration to an interval, then add it to the start time to calculate the event's end_timestamp.

{
"start_timestamp": 1728582889,
"duration": 120
}

Example query

create end_timestamp from addTime(start_timestamp, duration.toInterval('s'))

Example output

{
"start_timestamp": 1728582889,
"duration": 120,
"end_timestamp": 1728583009
}
Was this page helpful?