Copy as Markdown[Open in ChatGPT](https://chatgpt.com/?q=Read%20https%3A%2F%2Fdocs-docusaurus.kinsta.page%2Fdataprime%2Flanguage-reference%2Ffunctions-reference%2Ftime%2Fsubtracttime.md%20and%20help%20me%20with%20my%20question%20about%20this%20Coralogix%20documentation%20page.)[Open in Claude](https://claude.ai/new?q=Read%20https%3A%2F%2Fdocs-docusaurus.kinsta.page%2Fdataprime%2Flanguage-reference%2Ffunctions-reference%2Ftime%2Fsubtracttime.md%20and%20help%20me%20with%20my%20question%20about%20this%20Coralogix%20documentation%20page.)

# `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](https://docs-docusaurus.kinsta.page/dataprime/language-reference/functions-reference/.md),<!-- --> **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

}
```
