# Time Window (/docs/reference/sql/functions/time-window)



This page describes the RawTree engine binary used to generate this reference. It does not define Query API support. Descriptions retain upstream ClickHouse terminology. See [SQL interface scope](/docs/reference/clickhouse-compatibility#service-interfaces).

hop [#hop]

A hopping time window has a fixed duration (`window_interval`) and hops by a specified hop interval (`hop_interval`). If the `hop_interval` is smaller than the `window_interval`, hopping windows are overlapping. Thus, records can be assigned to multiple windows.

Since one record can be assigned to multiple hop windows, the function only returns the bound of the first window when hop function is used without WINDOW VIEW.

**Syntax**

```sql
hop(time_attr, hop_interval, window_interval[, timezone])
```

**Arguments**

* `time_attr` — Date and time. [`DateTime`](/reference/data-types/datetime)
* `hop_interval` — Positive Hop interval. [`Interval`](/reference/data-types/int-uint)
* `window_interval` — Positive Window interval. [`Interval`](/reference/data-types/int-uint)
* `timezone` — Optional. Timezone name. [`String`](/reference/data-types/string)

**Returned value**

Returns the inclusive lower and exclusive upper bound of the corresponding hopping window. [`Tuple(DateTime, DateTime)`](/reference/data-types/tuple)

**Examples**

**Hopping window**

```sql title=Query
SELECT hop(now(), INTERVAL '1' DAY, INTERVAL '2' DAY)
```

```text title=Response
('2024-07-03 00:00:00','2024-07-05 00:00:00')
```

*Introduced in version 21.12.0.*

hopEnd [#hopend]

Returns the exclusive upper bound of the corresponding hopping window.

Since one record can be assigned to multiple hop windows, the function only returns the bound of the first window when hop function is used without `WINDOW VIEW`.

**Syntax**

```sql
hopEnd(time_attr, hop_interval, window_interval[, timezone])
```

**Arguments**

* `time_attr` — Date and time. [`DateTime`](/reference/data-types/datetime)
* `hop_interval` — Positive Hop interval. [`Interval`](/reference/data-types/int-uint)
* `window_interval` — Positive Window interval. [`Interval`](/reference/data-types/int-uint)
* `timezone` — Optional. Timezone name. [`String`](/reference/data-types/string)

**Returned value**

Returns the exclusive upper bound of the corresponding hopping window. [`DateTime`](/reference/data-types/datetime)

**Examples**

**Hopping window end**

```sql title=Query
SELECT hopEnd(now(), INTERVAL '1' DAY, INTERVAL '2' DAY)
```

```text title=Response
2024-07-05 00:00:00
```

*Introduced in version 22.1.0.*

hopStart [#hopstart]

Returns the inclusive lower bound of the corresponding hopping window.

Since one record can be assigned to multiple hop windows, the function only returns the bound of the first window when hop function is used without `WINDOW VIEW`.

**Syntax**

```sql
hopStart(time_attr, hop_interval, window_interval[, timezone])
```

**Arguments**

* `time_attr` — Date and time. [`DateTime`](/reference/data-types/datetime)
* `hop_interval` — Positive Hop interval. [`Interval`](/reference/data-types/int-uint)
* `window_interval` — Positive Window interval. [`Interval`](/reference/data-types/int-uint)
* `timezone` — Optional. Timezone name. [`String`](/reference/data-types/string)

**Returned value**

Returns the inclusive lower bound of the corresponding hopping window. [`DateTime`](/reference/data-types/datetime)

**Examples**

**Hopping window start**

```sql title=Query
SELECT hopStart(now(), INTERVAL '1' DAY, INTERVAL '2' DAY)
```

```text title=Response
2024-07-03 00:00:00
```

*Introduced in version 22.1.0.*

tumble [#tumble]

A tumbling time window assigns records to non-overlapping, continuous windows with a fixed duration (`interval`).

**Syntax**

```sql
tumble(time_attr, interval[, timezone])
```

**Arguments**

* `time_attr` — Date and time. [`DateTime`](/reference/data-types/datetime)
* `interval` — Window interval in Interval. [`Interval`](/reference/data-types/int-uint)
* `timezone` — Optional. Timezone name. [`String`](/reference/data-types/string)

**Returned value**

Returns the inclusive lower and exclusive upper bound of the corresponding tumbling window. [`Tuple(DateTime, DateTime)`](/reference/data-types/tuple)

**Examples**

**Tumbling window**

```sql title=Query
SELECT tumble(now(), toIntervalDay('1'))
```

```text title=Response
('2024-07-04 00:00:00','2024-07-05 00:00:00')
```

*Introduced in version 21.12.0.*

tumbleEnd [#tumbleend]

Returns the exclusive upper bound of the corresponding tumbling window.

**Syntax**

```sql
tumbleEnd(time_attr, interval[, timezone])
```

**Arguments**

* `time_attr` — Date and time. [`DateTime`](/reference/data-types/datetime)
* `interval` — Window interval in Interval. [`Interval`](/reference/data-types/int-uint)
* `timezone` — Optional. Timezone name. [`String`](/reference/data-types/string)

**Returned value**

Returns the exclusive upper bound of the corresponding tumbling window. [`DateTime`](/reference/data-types/datetime)

**Examples**

**Tumbling window end**

```sql title=Query
SELECT tumbleEnd(now(), toIntervalDay('1'))
```

```text title=Response
2024-07-05 00:00:00
```

*Introduced in version 22.1.0.*

tumbleStart [#tumblestart]

Returns the inclusive lower bound of the corresponding tumbling window.

**Syntax**

```sql
tumbleStart(time_attr, interval[, timezone])
```

**Arguments**

* `time_attr` — Date and time. [`DateTime`](/reference/data-types/datetime)
* `interval` — Window interval in Interval. [`Interval`](/reference/data-types/int-uint)
* `timezone` — Optional. Timezone name. [`String`](/reference/data-types/string)

**Returned value**

Returns the inclusive lower bound of the corresponding tumbling window. [`DateTime`](/reference/data-types/datetime)

**Examples**

**Tumbling window start**

```sql title=Query
SELECT tumbleStart(now(), toIntervalDay('1'))
```

```text title=Response
2024-07-04 00:00:00
```

*Introduced in version 22.1.0.*

windowID [#windowid]

Returns the window identifier of the corresponding tumbling or hopping window.
This function can only be used with `WINDOW VIEW`.

**Syntax**

```sql
windowID(time_attr, interval[, timezone])
```

**Arguments**

* `time_attr` — Date and time. [`DateTime`](/reference/data-types/datetime)
* `interval` — Window interval in Interval. [`Interval`](/reference/data-types/int-uint)
* `timezone` — Optional. Timezone name. [`String`](/reference/data-types/string)

**Returned value**

Returns the window identifier of the corresponding window. [`UInt32`](/reference/data-types/int-uint)

**Examples**

**Window ID**

```sql title=Query
SELECT windowID(now(), toIntervalDay('1'))
```

*Introduced in version 22.1.0.*
