# `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/index.md), **function** and **method** notation. These interchangeable forms allow flexibility in how you structure expressions.

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

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

```json
{
  "start_time": 1728763337,
  "duration_seconds": 50
}
```

### Example query

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

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

### Example output

```json
{
  "start_time": 1728763337,
  "duration_seconds": 50,
  "end_time": 1728763387
}
```
