Skip to content

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 notation. These interchangeable forms allow flexibility in how you structure expressions.

subtractTime(t: timestamp, i: interval): timestamp
(t: timestamp).subtractTime(i: interval): timestamp

Arguments

NameTypeRequiredDescription
ttimestamptrueThe timestamp to modify
iintervaltrueThe 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"
}
create time_started from subtractTime(timestamp, time_taken_s.toInterval('s'))
create time_started from timestamp.subtractTime(time_taken_s.toInterval('s'))

Output

{
"timestamp": 1728763337000000000,
"time_taken_s": 500,
"event": "COMPLETE",
"time_started": 1728762837000000000
}