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

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

```
diffTime(to: timestamp, from: timestamp): interval
```

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

```
{

  "processing_start_time": 1728636298,

  "processing_end_time": 1728636358

}
```

### Example query

* Function notation
* Method notation

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

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

### Example output

```
{

  "processing_start_time": 1728636298,

  "processing_end_time": 1728636358,

  "time_taken_duration": "50s"

}
```
