Skip to main content
Skip to main content

Time

The Time data type is used to store a time value independent of any calendar date. It is ideal for representing daily schedules, event times, or any situation where only the time component (hours, minutes, seconds) is important.

Syntax:

Time()

Supported range of values: [-999:59:59, 999:59:59].

Resolution: 1 second.

Speed

The Date data type is faster than Time under most conditions. But the Time data type is around the same as DateTime data type.

Due to the implementation details, the Time and DateTime type requires 4 bytes of storage, while Date requires 2 bytes. However, during compression, the size difference between Date and Time becomes more significant.

Usage Remarks

The point in time is saved as a Unix timestamp, regardless of the time zone or daylight saving time.

Note: The Time data type does not observe time zones. It represents a time‐of‐day value on its own, without any date or regional offset context. Attempting to apply or change a time zone on Time columns has no effect and is not supported.

Examples

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

CREATE TABLE dt
(
    `time` Time,
    `event_id` UInt8
)
ENGINE = TinyLog;
-- Parse Time
-- - from string,
-- - from integer interpreted as number of seconds since 1970-01-01.
INSERT INTO dt VALUES ('100:00:00', 1), (12453, 3);

SELECT * FROM dt;
   ┌──────time─┬─event_id─┐
1. │ 100:00:00 │        1 │
2. │  03:27:33 │        3 │
   └───────────┴──────────┘

2. Filtering on Time values

SELECT * FROM dt WHERE time = toTime('100:00:00')
   ┌──────time─┬─event_id─┐
1. │ 100:00:00 │        1 │
   └───────────┴──────────┘

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

SELECT * FROM dt WHERE time = '100:00:00'
   ┌──────time─┬─event_id─┐
1. │ 100:00:00 │        1 │
   └───────────┴──────────┘

3. Getting a time zone for a Time-type column:

SELECT toTime(now()) AS column, toTypeName(column) AS x
   ┌────column─┬─x────┐
1. │  18:55:15 │ Time │
   └───────────┴──────┘

See Also