> ## Documentation Index
> Fetch the complete documentation index at: https://private-7c7dfe99-mintlify-3a82795f.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

> Documentation for the Time data type in ClickHouse, which stores the time range with second precision

# Time

Data type `Time` represents a time with hour, minute, and second components.
It is independent of any calendar date and is suitable for values which do not need day, months and year components.

Syntax:

```sql theme={null}
Time
```

Text representation range: \[-999:59:59, 999:59:59].

Resolution: 1 second.

<h2 id="implementation-details">
  Implementation details
</h2>

**Representation and Performance**.
Data type `Time` internally stores a signed 32-bit integer that encodes the seconds.
Values of type `Time` and `DateTime` have the same byte size and thus comparable performance.

**Normalization**.
When parsing strings to `Time`, the time components are normalized and not validated.
For example, `25:70:70` is interpreted as `26:11:10`.

**Negative values**.
Leading minus signs are supported and preserved.
Negative values typically arise from arithmetic operations on `Time` values.
For `Time` type, negative inputs are preserved for both text (e.g., `'-01:02:03'`) and numeric inputs (e.g., `-3723`).

**Saturation**.
The time-of-day component is capped to the range \[-999:59:59, 999:59:59].
Values with hours beyond 999 (or below -999) are represented and round-tripped via text as `999:59:59` (or `-999:59:59`).

**Time zones**.
`Time` does not support time zones, i.e. `Time` value are interpreted without regional context.
Specifying a time zone for `Time` as a type parameter or during value creation throws an error.
Likewise, attempts to apply or change the time zone on `Time` columns are not supported and result in an error.
`Time` values are not silently reinterpreted under different time zones.

<h2 id="examples">
  Examples
</h2>

**1.** Creating a table with a `Time`-type column and inserting data into it:

```sql theme={null}
CREATE TABLE tab
(
    `event_id` UInt8,
    `time` Time
)
ENGINE = TinyLog;
```

```sql theme={null}
-- Parse Time
-- - from string,
-- - from integer interpreted as number of seconds since 00:00:00.
INSERT INTO tab VALUES (1, '14:30:25'), (2, 52225);

SELECT * FROM tab ORDER BY event_id;
```

```text theme={null}
   ┌─event_id─┬──────time─┐
1. │        1 │ 14:30:25 │
2. │        2 │ 14:30:25 │
   └──────────┴───────────┘
```

**2.** Filtering on `Time` values

```sql theme={null}
SET use_legacy_to_time = 0;
SELECT * FROM tab WHERE time = toTime('14:30:25')
```

```text theme={null}
   ┌─event_id─┬──────time─┐
1. │        1 │ 14:30:25 │
2. │        2 │ 14:30:25 │
   └──────────┴───────────┘
```

`Time` column values can be filtered using a string value in `WHERE` predicate. It will be converted to `Time` automatically:

```sql theme={null}
SELECT * FROM tab WHERE time = '14:30:25'
```

```text theme={null}
   ┌─event_id─┬──────time─┐
1. │        1 │ 14:30:25 │
2. │        2 │ 14:30:25 │
   └──────────┴───────────┘
```

**3.** Inspecting the resulting type:

```sql theme={null}
SELECT CAST('14:30:25' AS Time) AS column, toTypeName(column) AS type
```

```text theme={null}
   ┌────column─┬─type─┐
1. │ 14:30:25 │ Time │
   └───────────┴──────┘
```

<h2 id="addition-with-date">
  Addition with Date
</h2>

A [Time](/reference/data-types/time) value can be added to a [Date](/reference/data-types/date) or [Date32](/reference/data-types/date32) value to produce a [DateTime](/reference/data-types/datetime) or [DateTime64](/reference/data-types/datetime64):

```sql theme={null}
SET use_legacy_to_time = 0;
SELECT toDate('2024-07-15') + toTime('14:30:25') as datetime;
```

```text theme={null}
   ┌────────────datetime─┐
1. │ 2024-07-15 14:30:25 │
   └─────────────────────┘
```

See [Date and Time Addition](/reference/operators#date-time-addition) for details on all supported combinations and result types.

<h2 id="see-also">
  See Also
</h2>

* [Type conversion functions](/reference/functions/regular-functions/type-conversion-functions)
* [Functions for working with dates and times](/reference/functions/regular-functions/date-time-functions)
* [Functions for working with arrays](/reference/functions/regular-functions/array-functions)
* [The `date_time_input_format` setting](/reference/settings/formats#date_time_input_format)
* [The `date_time_output_format` setting](/reference/settings/formats#date_time_output_format)
* [The `timezone` server configuration parameter](/reference/settings/server-settings/settings#timezone)
* [The `session_timezone` setting](/reference/settings/session-settings#session_timezone)
* [The `DateTime` data type](/reference/data-types/datetime)
* [The `Date` data type](/reference/data-types/date)
