Parses the ISO 8601 formatted date string into a date. The date can be a calendar date, a week date using ISO week numbering, or year and day of year combined.
Returns the timestamp specified in timestamp with the time zone converted from the session time zone to the time zone specified in zone with precision p. In the example below, the session time zone is set to America/New_York, which is three hours ahead of America/Los_Angeles.
Examples:
-- Retrieve the session time zoneSELECTcurrent_timezone();-- America/New_York-- Convert timestamp to a different time zoneSELECTat_timezone(TIMESTAMP'2022-11-01 09:08:07.321','America/Los_Angeles');-- 2022-11-01 06:08:07.321 America/Los_Angeles
Returns the timestamp specified in timestamp with the time zone specified in zone with precision p. In the example below, the session time zone is set to America/New_York.
Examples:
-- Retrieve the session time zoneSELECTcurrent_timezone();-- America/New_York-- Set timestamp to a different time zoneSELECTwith_timezone(TIMESTAMP'2022-11-01 09:08:07.321','America/Los_Angeles');-- 2022-11-01 09:08:07.321 America/Los_Angeles
Returns the UNIX timestamp unixtime as a timestamp with time zone. unixtime is the number of seconds since 1970-01-01 00:00:00 UTC.
from_unixtime(unixtime, zone)
Returns the UNIX timestamp unixtime as a timestamp with time zone using zone for the time zone. unixtime is the number of seconds since 1970-01-01 00:00:00 UTC.
from_unixtime(unixtime, hours, minutes)
Returns the UNIX timestamp unixtime as a timestamp with time zone using hours and minutes for the time zone offset. unixtime is the number of seconds since 1970-01-01 00:00:00 in double data type.
from_unixtime_nanos(unixtime)
Returns the UNIX timestamp unixtime as a timestamp with time zone. unixtime is the number of nanoseconds since 1970-01-01 00:00:00 UTC.
Examples:
- For from_unixtime(unixtime):
sql
SELECT from_unixtime(unixtime) AS result_timestamp;
-- Result: timestamp(3) with time zone
Formats x as an ISO 8601 string. x can be date, timestamp, or timestamp with time zone.
Example:
-- For dateSELECTto_iso8601(DATE'2022-05-31')ASiso8601_date_result;-- Result: "2022-05-31"-- For timestampSELECTto_iso8601(TIMESTAMP'2022-05-31 12:30:45')ASiso8601_timestamp_result;-- Result: "2022-05-31T12:30:45"-- For timestamp with time zoneSELECTto_iso8601(TIMESTAMP'2022-05-31 12:30:45+03:00')ASiso8601_timestamp_tz_result;-- Result: "2022-05-31T12:30:45+03:00"
The functions in this section use a format string that is compatible with the MySQL date_parse and str_to_date functions. The following table, based on the MySQL manual, describes the format specifiers:
Specifier
Description
%a
Abbreviated weekday name (Sun .. Sat)
%b
Abbreviated month name (Jan .. Dec)
%c
Month, numeric (1 .. 12), this specifier does not support 0 as a month.
%D
Day of the month with English suffix (0th, 1st, 2nd, 3rd, …)
%d
Day of the month, numeric (01 .. 31), this specifier does not support 0 as a month or day.
%e
Day of the month, numeric (1 .. 31), this specifier does not support 0 as a day.
%f
Fraction of second (6 digits for printing: 000000 .. 999000; 1 - 9 digits for parsing: 0 .. 999999999), timestamp is truncated to milliseconds.
%H
Hour (00 .. 23)
%h
Hour (01 .. 12)
%I
Hour (01 .. 12)
%i
Minutes, numeric (00 .. 59)
%j
Day of year (001 .. 366)
%k
Hour (0 .. 23)
%l
Hour (1 .. 12)
%M
Month name (January .. December)
%m
Month, numeric (01 .. 12), this specifier does not support 0 as a month.
%p
AM or PM
%r
Time of day, 12-hour (equivalent to %h:%i:%s %p)
%S
Seconds (00 .. 59)
%s
Seconds (00 .. 59)
%T
Time of day, 24-hour (equivalent to %H:%i:%s)
%U
Week (00 .. 53), where Sunday is the first day of the week
%u
Week (00 .. 53), where Monday is the first day of the week
%V
Week (01 .. 53), where Sunday is the first day of the week; used with %X
%v
Week (01 .. 53), where Monday is the first day of the week; used with %x
%W
Weekday name (Sunday .. Saturday)
%w
Day of the week (0 .. 6), where Sunday is the first day of the week, this specifier is not supported, consider using day_of_week() (it uses 1-7 instead of 0-6).
%X
Year for the week where Sunday is the first day of the week, numeric, four digits; used with %V
%x
Year for the week, where Monday is the first day of the week, numeric, four digits; used with %v
%Y
Year, numeric, four digits
%y
Year, numeric (two digits), when parsing, two-digit year format assumes range 1970 .. 2069, so “70” will result in year 1970 but “69” will produce 2069.