Type conversion functions

The input value is treated as a Unix timestamp with millisecond precision (number of milliseconds since 1970-01-01 00:00:00 UTC).

**Syntax**

```
fromUnixTimestamp64Milli(value[, timezone])
```

**Arguments**

- `value` — Unix timestamp in milliseconds. [`Int64`](/docs/sql-reference/data-types/int-uint)
- `timezone` — Optional. Timezone for the returned value. [`String`](/docs/sql-reference/data-types/string)

**Returned value**

A `DateTime64` value with millisecond precision. [`DateTime64(3)`](/docs/sql-reference/data-types/datetime64)

**Examples**

**Usage example**

```
SELECT fromUnixTimestamp64Milli(1640995200123)
```

```
┌─fromUnixTimestamp64Milli(1640995200123)─┐
│                 2022-01-01 00:00:00.123 │
└─────────────────────────────────────────┘
```

## fromUnixTimestamp64Nano[​](#fromUnixTimestamp64Nano "Direct link to fromUnixTimestamp64Nano")

Introduced in: v20.5.0

Converts a Unix timestamp in nanoseconds to a [`DateTime64`](/docs/sql-reference/data-types/datetime64) value with nanosecond precision.

The input value is treated as a Unix timestamp with nanosecond precision (number of nanoseconds since 1970-01-01 00:00:00 UTC).

Note

Please note that the input value is treated as a UTC timestamp, not the timezone of the input value.

**Syntax**

```
fromUnixTimestamp64Nano(value[, timezone])
```

**Arguments**

- `value` — Unix timestamp in nanoseconds. [`Int64`](/docs/sql-reference/data-types/int-uint)
- `timezone` — Optional. Timezone for the returned value. [`String`](/docs/sql-reference/data-types/string)

**Returned value**

Returns a `DateTime64` value with nanosecond precision. [`DateTime64(9)`](/docs/sql-reference/data-types/datetime64)

**Examples**

**Usage example**

```
SELECT fromUnixTimestamp64Nano(1640995200123456789)
```

```
┌─fromUnixTimestamp64Nano(1640995200123456789)─┐
│                2022-01-01 00:00:00.123456789 │
└──────────────────────────────────────────────┘
```

## fromUnixTimestamp64Second[​](#fromUnixTimestamp64Second "Direct link to fromUnixTimestamp64Second")

Introduced in: v24.12.0

Converts a Unix timestamp in seconds to a `DateTime64` value with second precision.

The input value is treated as a Unix timestamp with second precision (number of seconds since 1970-01-01 00:00:00 UTC).

**Syntax**

```
fromUnixTimestamp64Second(value[, timezone])
```

**Arguments**

- `value` — Unix timestamp in seconds. [`Int64`](/docs/sql-reference/data-types/int-uint)
- `timezone` — Optional. Timezone for the returned value. [`String`](/docs/sql-reference/data-types/string)

**Returned value**

Returns a `DateTime64` value with second precision. [`DateTime64(0)`](/docs/sql-reference/data-types/datetime64)

**Examples**

**Usage example**

```
SELECT fromUnixTimestamp64Second(1640995200)
```

```
┌─fromUnixTimestamp64Second(1640995200)─┐
│                   2022-01-01 00:00:00 │
└───────────────────────────────────────┘
```

## parseDateTime[​](#parseDateTime "Direct link to parseDateTime")

Introduced in: v23.3.0

Parses a date and time string according to a MySQL date format string.

This function is the inverse of [`formatDateTime`](/docs/sql-reference/functions/date-time-functions).
It parses a String argument using a format String. Returns a DateTime type.

**Syntax**

```
parseDateTime(time_string, format[, timezone])
```

**Aliases**: `TO_UNIXTIME`

**Arguments**

- `time_string` — String to be parsed into DateTime. [`String`](/docs/sql-reference/data-types/string)
- `format` — Format string specifying how to parse time\_string. [`String`](/docs/sql-reference/data-types/string)
- `timezone` — Optional. Timezone. [`String`](/docs/sql-reference/data-types/string)

**Returned value**

Returns a DateTime parsed from the input string according to the MySQL style format string. [`DateTime`](/docs/sql-reference/data-types/datetime)

**Examples**

**Usage example**

```
SELECT parseDateTime('2025-01-04+23:00:00', '%Y-%m-%d+%H:%i:%s')
```

```
┌─parseDateTime('2025-01-04+23:00:00', '%Y-%m-%d+%H:%i:%s')─┐
│                                       2025-01-04 23:00:00 │
└───────────────────────────────────────────────────────────┘
```

## parseDateTime32BestEffort[​](#parseDateTime32BestEffort "Direct link to parseDateTime32BestEffort")

Introduced in: v20.9.0

Converts a string representation of a date and time to the [`DateTime`](/docs/sql-reference/data-types/datetime) data type.

The function parses [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601), [RFC 1123 - 5.2.14 RFC-822 Date and Time Specification](https://tools.ietf.org/html/rfc1123#page-55), ClickHouse's and some other date and time formats.

**Syntax**

```
parseDateTime32BestEffort(time_string[, time_zone])
```

**Arguments**

- `time_string` — String containing a date and time to convert. [`String`](/docs/sql-reference/data-types/string)
- `time_zone` — Optional. Time zone according to which `time_string` is parsed [`String`](/docs/sql-reference/data-types/string)

**Returned value**

Returns `time_string` as a `DateTime`. [`DateTime`](/docs/sql-reference/data-types/datetime)

**Examples**

**Usage example**

```
SELECT parseDateTime32BestEffort('23/10/2025 12:12:57')
AS parseDateTime32BestEffort
```

```
┌─parseDateTime32BestEffort─┐
│       2025-10-23 12:12:57 │
└───────────────────────────┘
```

**With timezone**

```
SELECT parseDateTime32BestEffort('Sat, 18 Aug 2025 07:22:16 GMT', 'Asia/Istanbul')
AS parseDateTime32BestEffort
```

```
┌─parseDateTime32BestEffort─┐
│       2025-08-18 10:22:16 │
└───────────────────────────┘
```

**Unix timestamp**

```
SELECT parseDateTime32BestEffort('1284101485')
AS parseDateTime32BestEffort
```

```
┌─parseDateTime32BestEffort─┐
│       2015-07-07 12:04:41 │
└───────────────────────────┘
```

## parseDateTime32BestEffortOrNull[​](#parseDateTime32BestEffortOrNull "Direct link to parseDateTime32BestEffortOrNull")

Introduced in: v20.9.0

Same as [`parseDateTime32BestEffort`](#parseDateTime32BestEffort) except that it returns `NULL` when it encounters a date format that cannot be processed.

**Syntax**

```
parseDateTime32BestEffortOrNull(time_string[, time_zone])
```

**Arguments**

- `time_string` — String containing a date and time to convert. [`String`](/docs/sql-reference/data-types/string)
- `time_zone` — Optional. Time zone according to which `time_string` is parsed. [`String`](/docs/sql-reference/data-types/string)

**Returned value**

Returns a `DateTime` object parsed from the string, or `NULL` if the parsing fails. [`DateTime`](/docs/sql-reference/data-types/datetime)

**Examples**

**Usage example**

```
SELECT
    parseDateTime32BestEffortOrNull('23/10/2025 12:12:57') AS valid,
    parseDateTime32BestEffortOrNull('invalid date') AS invalid
```

```
┌─valid───────────────┬─invalid─┐
│ 2025-10-23 12:12:57 │    ᴺᵁᴸᴸ │
└─────────────────────┴─────────┘
```

## parseDateTime32BestEffortOrZero[​](#parseDateTime32BestEffortOrZero "Direct link to parseDateTime32BestEffortOrZero")

Introduced in: v20.9.0

Same as [`parseDateTime32BestEffort`](#parseDateTime32BestEffort) except that it returns a zero date or a zero date time when it encounters a date format that cannot be processed.

**Syntax**

```
parseDateTime32BestEffortOrZero(time_string[, time_zone])
```

**Arguments**

- `time_string` — String containing a date and time to convert. [`String`](/docs/sql-reference/data-types/string)
- `time_zone` — Optional. Time zone according to which `time_string` is parsed. [`String`](/docs/sql-reference/data-types/string)

**Returned value**

Returns a `DateTime` object parsed from the string, or zero date (`1970-01-01 00:00:00`) if the parsing fails. [`DateTime`](/docs/sql-reference/data-types/datetime)

**Examples**

**Usage example**

```
SELECT
    parseDateTime32BestEffortOrZero('23/10/2025 12:12:57') AS valid,
    parseDateTime32BestEffortOrZero('invalid date') AS invalid
```

```
┌─valid───────────────┬─invalid─────────────┐
│ 2025-10-23 12:12:57 │ 1970-01-01 00:00:00 │
└─────────────────────┴─────────────────────┘
```

## parseDateTime64[​](#parseDateTime64 "Direct link to parseDateTime64")

Introduced in: v24.11.0