# `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://coralogix.com/docs/dataprime/language-reference/functions-reference/index.md), **function** and **method** notation. These interchangeable forms allow flexibility in how you structure expressions.

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

```dataprime
(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.

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

### Example query

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

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

### Example output

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