subtractTime
Description
Returns a timestamp reduced by a given interval.
note
Equivalent to addTime(t, -i) or t - i, where t is a timestamp and i is an interval.
Syntax
Like many functions in DataPrime, subtractTime supports two notations, function and method. These interchangeable forms allow flexibility in how you structure expressions.
- Function notation
- Method notation
subtractTime(t: timestamp, i: interval): timestamp
(t: timestamp).subtractTime(i: interval): timestamp
Arguments
| Name | Type | Required | Description |
|---|---|---|---|
t | timestamp | true | The timestamp to modify |
i | interval | true | The interval to subtract from the timestamp |
Example
Use case: Calculate process start time
A log records a completion timestamp and a process duration in seconds. Convert the duration to an interval and subtract it from the completion time to calculate when the process started.
{
"timestamp": 1728763337000000000,
"time_taken_s": 500,
"event": "COMPLETE"
}
Example query
- Function notation
- Method notation
create time_started from subtractTime(timestamp, time_taken_s.toInterval('s'))
create time_started from timestamp.subtractTime(time_taken_s.toInterval('s'))
Example output
{
"timestamp": 1728763337000000000,
"time_taken_s": 500,
"event": "COMPLETE",
"time_started": 1728762837000000000
}