ClickHouse/docs/en/data_types/datetime.md
BayoNet 99210b24a9
DOCS-4146: Updated the description of the DateTime data type. (#7429)
* Typo fix.

* elenbaskakova-DOCSUP-52 (#66)

The article "Time Zones" has been expanded.

* DOCAPI-4146: DateTime rewrited.

* DOCAPI-4146: Update after the review.
2019-11-06 13:03:06 +03:00

2.9 KiB

DateTime

Data structure storing Unix timestamp. Also, it can store a time zone.

Syntax:

DateTime([timezone])

Range of values in the Unix timestamp: [1970-01-01 00:00:00, 2105-12-31 23:59:59].

Resolution: 1 second.

Usage remarks

ClickHouse stores date and time values in the Unix timestamp format that is independent of the time zones and daylight saving rules. The time zone value affects displaying DateTime values in text formats and parsing the input strings for storage. You can find the list of supported time zones in IANA Time Zone Database.

You can explicitly set a time zone for DateTime-type column when creating a table. If time zone isn't set, ClickHouse uses the value of the timezone server configuration parameter or the operating system settings at the moment of the ClickHouse server start.

The clickhouse-client applies the server time zone by default if a time zone isn't explicitly defined when initializing the data type. To use the client time zone, run it with the --use_client_time_zone parameter.

ClickHouse outputs values in the YYYY-MM-DD hh:mm:ss text format by default. You can change the format with the formatDateTime function.

When inserting data into ClickHouse, you can use different formats of date and time strings, depending on the date_time_input_format setting value.

Examples

Creating a table with a DateTime-type column:

CREATE TABLE dt(
    timestamp DateTime('Europe/Moscow')
)

Getting a time zone for a DateTime-type value:

SELECT
    toDateTime(now(), 'Europe/Moscow') AS column,
    toTypeName(column) AS x
┌──────────────column─┬─x─────────────────────────┐
│ 2019-10-16 04:12:04 │ DateTime('Europe/Moscow') │
└─────────────────────┴───────────────────────────┘

See Also

Original article