Skip to content

subtractTime - Subtract a given interval from a timestamp

The subtractTime function will alter a timestamp by a given interval.

Note

This is equivalent to addTime(t, -i) and t - i where t is some timestamp and i is some 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.

timeRound(date: timestamp, interval: interval): timestamp
date: timestamp.timeRound(interval: interval): timestamp

Arguments

NameTypeRequiredDescription
ttimestamptrueThe timestamp to be subtracted
iintervaltrueThe interval whose value will be subtracted from the timestamp

Example - Calculating start time

Consider the following document:

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

We want to understand when the process began. We can do this by first converting time_taken_s into an interval, and subtracting it from the timestamp:

create time_started from subtractTime(timestamp, time_taken_s.toInterval('s'))
create time_started from timestamp.subtractTime(time_taken_s.toInterval('s'))

This results in the following document:

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

Try it yourself

Enter the explore screen in Coralogix and paste this DataPrime Query:

create timestamp from now()
| create time_taken_s from 600
| create time_started from timestamp.subtractTime(time_taken_s.toInterval('s'))