# `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](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
subtractInterval(left: interval, right: interval): interval
```

```dataprime
(left: interval).subtractInterval(right: interval): interval
```

## Arguments

| Name  | Type     | Required | Description                   |
| ----- | -------- | -------- | ----------------------------- |
| left  | interval | **true** | The interval to subtract from |
| right | interval | **true** | The 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.

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

### Example query

```dataprime
create idle_time from subtractInterval(total_time_taken, loading_time_taken + processing_time_taken)
```

```dataprime
create idle_time from total_time_taken.subtractInterval(loading_time_taken + processing_time_taken)
```

### Example output

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