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

# `roundTime`

## Description

Returns a timestamp rounded down to the nearest interval.

Note

Functionally equivalent to dividing a timestamp by an interval: `timestamp / interval`.

## Syntax

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

```
roundTime(sourceTimestamp: timestamp, timeInterval: interval): timestamp
```

```
(sourceTimestamp: timestamp).roundTime(timeInterval: interval): timestamp
```

## Arguments

| Name              | Type        | Required | Description                                      |
| ----------------- | ----------- | -------- | ------------------------------------------------ |
| `sourceTimestamp` | `timestamp` | **true** | The timestamp to round                           |
| `timeInterval`    | `interval`  | **true** | The interval that defines the rounding precision |

## Example

**Use case: Group timestamps into one-hour buckets**

Round event timestamps to one-hour buckets and count `CREATE` actions per bucket.

### Example data

```
{ "ts": 1728763337, "action": "CREATE" },

{ "ts": 1728751234, "action": "CREATE" },

{ "ts": 1728734567, "action": "UPDATE" },

{ "ts": 1728763312, "action": "DELETE" }
```

### Example query

* Function notation
* Method notation

```
filter action == "CREATE"

| groupby roundTime(ts, 1h) as time_bucket agg count() as create_count
```

```
filter action == "CREATE"

| groupby ts.roundTime(1h) as time_bucket agg count() as create_count
```

### Example output

```
{ "time_bucket": 1728763200000000000, "create_count": 2 },

{ "time_bucket": 1728748800000000000, "create_count": 1 },

{ "time_bucket": 1728734400000000000, "create_count": 1 }
```
