# `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://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
roundInterval(interval: interval, scale: timeunit): interval
```

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

```json
{ "duration": "2h10m15s", ... },
{ "duration": "3h8m15s", ... },
{ "duration": "5d2h22m46s", ... },
{ "duration": "53m15s", ... }
```

### Example query

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

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

### Example output

```json
{ "duration": "2h10m15s", "time_bucket": "2h", ... },
{ "duration": "5d2h22m46s",  "time_bucket": "5d2h", ... },
{ "duration": "3h10m15s", "time_bucket": "3h", ... },
{ "duration": "53m15s",   "time_bucket": "0ns", ... }
```
