Copy as Markdown[Open in ChatGPT](https://chatgpt.com/?q=Read%20https%3A%2F%2Fdocs-docusaurus.kinsta.page%2Fdataprime%2Flanguage-reference%2Ffunctions-reference%2Ftime%2Fsubtractinterval.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%2Fsubtractinterval.md%20and%20help%20me%20with%20my%20question%20about%20this%20Coralogix%20documentation%20page.)

# `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://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

```
subtractInterval(left: interval, right: interval): interval
```

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

```
{

    "event": "PROCESSING_COMPLETE",

    "timestamp": 1728763337,

    "total_time_taken": "1m",

    "processing_time_taken": "30s",

    "loading_time_taken": "28s"

}
```

### Example query

* Function notation
* Method notation

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

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

### Example output

```
{

    "event": "PROCESSING_COMPLETE",

    "timestamp": 1728763337,

    "total_time_taken": "1m",

    "processing_time_taken": "30s",

    "loading_time_taken": "28s",

    "idle_time": "2s"

}
```
