# ceil, floor

[Read this page in HTML](https://www.scopedb.io/docs/reference/functions/date-and-time/temporal-round)

Rounds a timestamp up or down to a multiple of a time unit.

## Syntax

```scopeql
ceil(<timestamp>, n => <n>, unit => <unit>)
floor(<timestamp>, n => <n>, unit => <unit>)
```

## Arguments

| Argument      | Type        | Description                                                                                                              |
| ------------- | ----------- | ------------------------------------------------------------------------------------------------------------------------ |
| `<timestamp>` | `timestamp` | Timestamp to round.                                                                                                      |
| `n`           | `int`       | Constant. Positive number of units per boundary. Must not be NULL.                                                       |
| `unit`        | `string`    | Constant. Unit: `'hour'`, `'minute'`, `'second'`, `'millisecond'`, `'microsecond'`, or `'nanosecond'`. Must not be NULL. |

## Returns

Returns `timestamp`, or NULL for a NULL input.

* `ceil` returns the smallest boundary timestamp greater than or equal to the input.
* `floor` returns the greatest boundary timestamp less than or equal to the input.
* A timestamp already on a boundary stays unchanged.

## Usage notes

Boundaries are measured from the Unix epoch in UTC.

## Examples

Find the lower and upper quarter-hour boundaries around an event timestamp.

```scopeql
VALUES ('2026-06-01T10:07:32Z'), ('2026-06-01T10:15:00Z')
SELECT $0::timestamp AS event_time
SELECT
    event_time,
    floor(event_time, n => 15, unit => 'minute') AS lower_bound,
    ceil(event_time, n => 15, unit => 'minute') AS upper_bound
```

```text
+----------------------+----------------------+----------------------+
| event_time           | lower_bound          | upper_bound          |
+----------------------+----------------------+----------------------+
| 2026-06-01T10:07:32Z | 2026-06-01T10:00:00Z | 2026-06-01T10:15:00Z |
| 2026-06-01T10:15:00Z | 2026-06-01T10:15:00Z | 2026-06-01T10:15:00Z |
+----------------------+----------------------+----------------------+
```

An event exactly on a boundary stays there in both results. If you need the end of a half-open window, add 15 minutes to its lower bound.
