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.
- Function notation
- Method notation
addTime(t: timestamp, i: interval): timestamp
(t: timestamp).addTime(i: interval): timestamp
Arguments
| Name | Type | Required | Description |
|---|---|---|---|
t | timestamp | true | The base timestamp to modify |
i | interval | true | The 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
- Function notation
- Method notation
create end_timestamp from addTime(start_timestamp, duration.toInterval('s'))
create end_timestamp from start_timestamp.addTime(duration.toInterval('s'))
Example output
{
"start_timestamp": 1728582889,
"duration": 120,
"end_timestamp": 1728583009
}