# `addInterval`

## Description

Returns the sum of two intervals as a single interval value.

For example, adding an interval of `1d` (one day) to another `1d` produces `2d` (two days).

Note

This function also supports negative intervals. For example, `1d + -1h` results in `23h`, following standard arithmetic rules where adding a negative is equivalent to subtraction.

## Syntax

Like many functions in DataPrime, `addInterval` 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
addInterval(left: interval, right: interval): interval
```

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

## Arguments

| Name  | Type     | Required | Description                |
| ----- | -------- | -------- | -------------------------- |
| left  | interval | **true** | The first interval to add  |
| right | interval | **true** | The second interval to add |

## Example

**Use case: Compute total processing time across different units**

A document contains both a loading duration in milliseconds and processing timestamps in seconds. To compute the full duration of the transaction, convert the millisecond value to an interval, compute the processing interval, and add them together.

```json
{
    "loading_duration_ms": 5432,
    "processing_start_time": 1728582889,
    "processing_end_time": 1728582899
}
```

### Example query

```dataprime
create processing_duration from diffTime(processing_start_time, processing_end_time)
| create total_duration from addInterval(loading_duration_ms.toInterval('ms'), processing_duration)
```

```dataprime
create processing_duration from processing_start_time.diffTime(processing_end_time)
| create total_duration from addInterval(loading_duration_ms.toInterval('ms'), processing_duration)
```

### Example output

```json
{
    "loading_duration_ms": 5432,
    "processing_start_time": 1728582889,
    "processing_end_time": 1728582899,
    "processing_duration": "10s",
    "total_duration": "15432ms"
}
```
