---
title: 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.
url: https://coralogix.com/docs/dataprime/language-reference/functions-reference/time/tointerval/
product: dataengine
feature: DataPrime Language
feature_id: dataprime-language
feature_identifier: dataengine/dataprime-language
last_updated: '2026-10-21'
---

# `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://coralogix.com/docs/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

}
```
