|
| 1 | +--- |
| 2 | +description: 'Documentation for the Time64 data type in ClickHouse, which stores |
| 3 | + the time range with sub-second precision' |
| 4 | +slug: /sql-reference/data-types/time64 |
| 5 | +sidebar_position: 17 |
| 6 | +sidebar_label: 'Time64' |
| 7 | +title: 'Time64' |
| 8 | +--- |
| 9 | + |
| 10 | +# Time64 |
| 11 | + |
| 12 | +The Time64 data type allows storing time values with sub-second precision. Unlike DateTime64, it does not include a calendar date, but only represents time. The precision defines the resolution of stored values in fractional seconds. |
| 13 | + |
| 14 | +Tick size (precision): 10<sup>-precision</sup> seconds. Valid range: [ 0 : 9 ]. |
| 15 | +Typically, are used - 3 (milliseconds), 6 (microseconds), 9 (nanoseconds). |
| 16 | + |
| 17 | +**Syntax:** |
| 18 | + |
| 19 | +``` sql |
| 20 | +Time64(precision) |
| 21 | +``` |
| 22 | + |
| 23 | +Internally, Time64 stores data as an Int64 number of ticks since the start of the day (000:00:00.000000000). The tick resolution is determined by the precision parameter. Optionally, a time zone can be specified at the column level, which affects how time values are interpreted and displayed in text format. |
| 24 | + |
| 25 | +Unlike DateTime64, Time64 does not store a date component, meaning that it only represents time. See details in [Time](../../sql-reference/data-types/time.md). |
| 26 | + |
| 27 | +Supported range of values: \[000:00:00, 999:59:59.99999999\] |
| 28 | + |
| 29 | +## Examples {#examples} |
| 30 | + |
| 31 | +1. Creating a table with `Time64`-type column and inserting data into it: |
| 32 | + |
| 33 | +``` sql |
| 34 | +CREATE TABLE t64 |
| 35 | +( |
| 36 | + `timestamp` Time64(3), |
| 37 | + `event_id` UInt8 |
| 38 | +) |
| 39 | +ENGINE = TinyLog; |
| 40 | +``` |
| 41 | + |
| 42 | +``` sql |
| 43 | +-- Parse Time |
| 44 | +-- - from integer interpreted as number of seconds since 1970-01-01. |
| 45 | +-- - from string, |
| 46 | +INSERT INTO t64 VALUES (15463123, 1), (154600.123, 2), ('100:00:00', 3); |
| 47 | + |
| 48 | +SELECT * FROM t64; |
| 49 | +``` |
| 50 | + |
| 51 | +``` text |
| 52 | + ┌─────timestamp─┬─event_id─┐ |
| 53 | +1. │ 004:17:43.123 │ 1 │ |
| 54 | +2. │ 042:56:40.123 │ 2 │ |
| 55 | +3. │ 100:00:00.000 │ 3 │ |
| 56 | + └───────────────┴──────────┘ |
| 57 | +``` |
| 58 | + |
| 59 | +2. Filtering on `Time64` values |
| 60 | + |
| 61 | +``` sql |
| 62 | +SELECT * FROM t64 WHERE timestamp = toTime64('100:00:00', 3); |
| 63 | +``` |
| 64 | + |
| 65 | +``` text |
| 66 | + ┌─────timestamp─┬─event_id─┐ |
| 67 | +1. │ 100:00:00.000 │ 3 │ |
| 68 | + └───────────────┴──────────┘ |
| 69 | +``` |
| 70 | + |
| 71 | +Unlike `Time`, `Time64` values are not converted from `String` automatically. |
| 72 | + |
| 73 | +``` sql |
| 74 | +SELECT * FROM t64 WHERE timestamp = toTime64(154600.123, 3); |
| 75 | +``` |
| 76 | + |
| 77 | +``` text |
| 78 | + ┌─────timestamp─┬─event_id─┐ |
| 79 | +1. │ 042:56:40.123 │ 2 │ |
| 80 | + └───────────────┴──────────┘ |
| 81 | +``` |
| 82 | + |
| 83 | +Contrary to inserting, the `toTime64` function will treat all values as the decimal variant, so precision needs to |
| 84 | +be given after the decimal point. |
| 85 | + |
| 86 | +3. Getting a time zone for a `Time64`-type value: |
| 87 | + |
| 88 | +``` sql |
| 89 | +SELECT toTime64(now(), 3) AS column, toTypeName(column) AS x; |
| 90 | +``` |
| 91 | + |
| 92 | +``` text |
| 93 | + ┌────────column─┬─x─────────┐ |
| 94 | +1. │ 019:14:16.000 │ Time64(3) │ |
| 95 | + └───────────────┴───────────┘ |
| 96 | +``` |
| 97 | + |
| 98 | + |
| 99 | +**See Also** |
| 100 | + |
| 101 | +- [Type conversion functions](../../sql-reference/functions/type-conversion-functions.md) |
| 102 | +- [Functions for working with dates and times](../../sql-reference/functions/date-time-functions.md) |
| 103 | +- [The `date_time_input_format` setting](../../operations/settings/settings-formats.md#date_time_input_format) |
| 104 | +- [The `date_time_output_format` setting](../../operations/settings/settings-formats.md#date_time_output_format) |
| 105 | +- [The `timezone` server configuration parameter](../../operations/server-configuration-parameters/settings.md#timezone) |
| 106 | +- [The `session_timezone` setting](../../operations/settings/settings.md#session_timezone) |
| 107 | +- [Operators for working with dates and times](../../sql-reference/operators/index.md#operators-for-working-with-dates-and-times) |
| 108 | +- [`Date` data type](../../sql-reference/data-types/date.md) |
| 109 | +- [`Time` data type](../../sql-reference/data-types/time.md) |
| 110 | +- [`DateTime` data type](../../sql-reference/data-types/datetime.md) |
0 commit comments