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

# `toInterval`

## Description

Returns an interval created from a numeric value and an optional time unit.

This function works with integers, decimals, positive, and negative values.

## Syntax

Like many functions in DataPrime, `toInterval` 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

```
toInterval(number: number, timeUnit?: timeunit): interval
```

```
(number: number).toInterval(timeUnit?: timeunit): interval
```

## Arguments

| Name       | Type       | Required  | Description                                    |
| ---------- | ---------- | --------- | ---------------------------------------------- |
| `number`   | `number`   | **true**  | The number to convert into an interval         |
| `timeUnit` | `timeunit` | **false** | The time unit of the value. Defaults to `nano` |

## Example

**Use case: Add numeric duration to a timestamp to compute an end time**

A log contains a `start_time` and a numeric duration in seconds. Convert the duration into an interval and add it to the timestamp.

```
{

  "start_time": 1728763337,

  "duration_seconds": 50

}
```

### Example query

* Function notation
* Method notation

```
create end_time from addTime(start_time, duration_seconds.toInterval('s'))
```

```
create end_time from start_time.addTime(duration_seconds.toInterval('s'))
```

### Example output

```
{

  "start_time": 1728763337,

  "duration_seconds": 50,

  "end_time": 1728763387

}
```
