Skip to content

subtractInterval

Description

Returns the result of subtracting one interval from another.

Note

Equivalent to addInterval(left, -right) or left - right.

Syntax

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

subtractInterval(left: interval, right: interval): interval
(left: interval).subtractInterval(right: interval): interval

Arguments

NameTypeRequiredDescription
leftintervaltrueThe interval to subtract from
rightintervaltrueThe interval to subtract

Example

Use case: Calculate idle time

A log tracks total time taken, as well as processing and loading durations. Subtract the sum of processing and loading from the total to compute idle time.

{
"event": "PROCESSING_COMPLETE",
"timestamp": 1728763337,
"total_time_taken": "1m",
"processing_time_taken": "30s",
"loading_time_taken": "28s"
}
create idle_time from subtractInterval(total_time_taken, loading_time_taken + processing_time_taken)
create idle_time from total_time_taken.subtractInterval(loading_time_taken + processing_time_taken)

Output

{
"event": "PROCESSING_COMPLETE",
"timestamp": 1728763337,
"total_time_taken": "1m",
"processing_time_taken": "30s",
"loading_time_taken": "28s",
"idle_time": "2s"
}