# `formatInterval`

## Description

Returns an interval rendered as a string, with optional control over which time unit is displayed.

## Syntax

Like many functions in DataPrime, `formatInterval` 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
formatInterval(interval: interval, scale?: timeunit): string
```

```dataprime
(interval: interval).formatInterval(scale?: timeunit): string
```

## Arguments

| Name     | Type     | Required  | Description                                                                           |
| -------- | -------- | --------- | ------------------------------------------------------------------------------------- |
| interval | interval | **true**  | The interval to format                                                                |
| scale    | timeunit | **false** | The largest unit to display. Does not cascade into smaller units. Defaults to `nano`. |

## Example

**Use case: Render an interval in seconds**

Even if the interval is 5 minutes, you may want to render it as `300s`. Use the `scale` argument to specify seconds.

```json
{
  "timestamp": 1728636298
}
```

### Example query

```dataprime
choose formatInterval(now() - $m.timestamp, 'seconds') as seconds_elapsed
```

```dataprime
choose (now() - $m.timestamp).formatInterval('seconds') as seconds_elapsed
```

### Example output

```json
{
  "seconds_elapsed": "300s"
}
```
