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

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

```
formatInterval(interval: interval, scale?: timeunit): string
```

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

```
{

  "timestamp": 1728636298

}
```

### Example query

* Function notation
* Method notation

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

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

### Example output

```
{

  "seconds_elapsed": "300s"

}
```
