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

# `roundInterval`

## Description

Returns an interval rounded down to a specified precision. All time units smaller than the specified `timeunit` are zeroed out.

## Syntax

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

```
roundInterval(interval: interval, scale: timeunit): interval
```

```
(interval: interval).roundInterval(scale: timeunit): interval
```

## Arguments

| Name       | Type       | Required | Description                                     |
| ---------- | ---------- | -------- | ----------------------------------------------- |
| `interval` | `interval` | **true** | The interval to round                           |
| `scale`    | `timeunit` | **true** | The unit to round to, zeroing out smaller units |

## Example

**Use case: Bucket intervals into whole hours**

Spans contain a `duration` interval in `$m` - the metadata. Use `roundInterval` to reduce precision to hours, then format and group by these buckets.

### Example data

```
{ "duration": "2h10m15s", ... },

{ "duration": "3h8m15s", ... },

{ "duration": "5d2h22m46s", ... },

{ "duration": "53m15s", ... }
```

### Example query

* Function notation
* Method notation

```
create time_bucket from roundInterval(duration, 'h')
```

```
create time_bucket from duration.roundInterval('h')
```

### Example output

```
{ "duration": "2h10m15s", "time_bucket": "2h", ... },

{ "duration": "5d2h22m46s",  "time_bucket": "5d2h", ... },

{ "duration": "3h10m15s", "time_bucket": "3h", ... },

{ "duration": "53m15s",   "time_bucket": "0ns", ... }
```
