# `diffTime`

## Description

Returns the duration between two timestamps as an interval.

The result is not the absolute difference:

- Positive if `to > from`
- Negative if `to < from`

## Syntax

Like many functions in DataPrime, `diffTime` 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
diffTime(to: timestamp, from: timestamp): interval
```

```dataprime
(to: timestamp).diffTime(from: timestamp): interval
```

## Arguments

| Name | Type      | Required | Description                                           |
| ---- | --------- | -------- | ----------------------------------------------------- |
| to   | timestamp | **true** | The timestamp to compare (typically the later time)   |
| from | timestamp | **true** | The timestamp to compare (typically the earlier time) |

## Example

**Use case: Measure process duration**

A document contains start and end timestamps for a process. Use `diffTime` to compute the elapsed interval.

```json
{
  "processing_start_time": 1728636298,
  "processing_end_time": 1728636358
}
```

### Example query

```dataprime
create time_taken_duration from diffTime(processing_start_time, processing_end_time)
```

```dataprime
create time_taken_duration from processing_start_time.diffTime(processing_end_time)
```

### Example output

```json
{
  "processing_start_time": 1728636298,
  "processing_end_time": 1728636358,
  "time_taken_duration": "50s"
}
```
