Convert a Unix epoch seconds value into a formatted date-time string.
FROM_UNIXTIME(unix_time [, fmt])
## Overview Converts an epoch value (seconds since 1970-01-01 00:00:00 UTC) to a formatted date-time string. When a format pattern is supplied, the output uses that pattern; otherwise a default 'yyyy-MM-dd HH:mm:ss' form is produced. Use FROM_UNIXTIME when your data stores epoch integers and you need a human-readable string for display or export. To get a typed TIMESTAMP instead of a string, use TO_TIMESTAMP with the epoch value. ## Behavior - Returns a VARCHAR. - Returns NULL if the input is NULL. - Input is seconds, not milliseconds. Divide millisecond epochs by 1000 before calling. - Fractional epoch values are accepted when the input type is DOUBLE; the fractional part contributes sub-second precision. - Without a format argument the output is 'yyyy-MM-dd HH:mm:ss' in the session time zone. - The format pattern uses percent-prefixed tokens consistent with DATE_FORMAT. ## Timezone handling - The formatted output is produced in the session time zone. - To emit UTC regardless of session, combine with AT TIME ZONE or cast the result of TO_TIMESTAMP(unix_time) AT TIME ZONE 'UTC' through DATE_FORMAT. ## Format specifiers FROM_UNIXTIME shares the percent-prefixed token family with DATE_FORMAT. Common tokens: %Y (year), %m (month), %d (day), %H (hour 00-23), %i (minute), %s (second), %f (microseconds), %W (weekday name), %M (full month name). See the DATE_FORMAT reference for the full list. ## Compatibility - Traditional seconds-based epoch conversion function. Millisecond-epoch variants are not provided: divide by 1000 first or build on TO_TIMESTAMP.
| Name | Type | Description |
|---|---|---|
unix_time | Specifies the Unix timestamp in seconds since 1970-01-01 00:00:00 UTC. For millisecond epochs, divide by 1000 before calling. | |
fmt | Specifies an optional format pattern for the output. When omitted, the default 'yyyy-MM-dd HH:mm:ss' form is produced. |
-- Default format for Jan 1 2025 UTC
SELECT FROM_UNIXTIME(1735689600) AS ts_string;
-- Custom percent-style format
SELECT FROM_UNIXTIME(1735689600, '%Y/%m/%d') AS d_string;
-- Epoch 0 is the Unix epoch itself
SELECT FROM_UNIXTIME(0) AS epoch_start;
-- Column-driven conversion
SELECT event_name, FROM_UNIXTIME(event_epoch, '%Y-%m-%d %H:%i:%s') AS event_time
FROM telemetry.ingest.raw_events;
-- Convert milliseconds to a timestamp string (divide by 1000)
SELECT FROM_UNIXTIME(ms_epoch / 1000, '%Y-%m-%d %H:%i:%s') AS ts
FROM telemetry.ingest.ms_events;
-- Round-trip with UNIX_TIMESTAMP
SELECT FROM_UNIXTIME(UNIX_TIMESTAMP('2025-06-15 12:00:00')) AS restored;