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

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

Arguments

Name Type Required Description
t timestamp true The timestamp to be subtracted
i interval true The 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 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'))