format_time¶
Description¶
Format a timestamp column according to the specified format string.
Format specifiers are detailed in Snowflake’s time format specifiers documentation
format_time
can be used to extract elements of a time, such as the year or hour.
The optional timezone
argument can be a time zone name or a link name from release 2021a of the IANA Time Zone Database (for example, America/Los_Angeles, Europe/London, UTC, Etc/GMT). Note that we do not support major timezone abbreviations (ex: PDT, EST, etc) because this can refer to several different time zones.
If the timezone
argument is not supplied, the timestamp will be interpreted as UTC.
Return type¶
string
Domain¶
This is a scalar function (calculates a single output value for a single input row.)
Categories¶
Usage¶
format_time(time, format, [ timezone ])
Argument |
Type |
Optional |
Repeatable |
Restrictions |
---|---|---|---|---|
time |
timestamp |
no |
no |
none |
format |
string |
no |
no |
constant |
timezone |
string |
yes |
no |
none |
Examples¶
make_col year:format_time(@."Valid From", "YYYY")
Extracts the year from the “Valid From” column
make_col formatted:format_time(@."Valid From", 'YYYY-MM-DD"T"HH24:MI:SSTZH:TZM')
Format the “Valid From” column according to ISO 8601
make_col formatted:format_time(@."Valid From", 'DY MON DD HH24:MI:SS YYYY')
Format the “Valid From” column similar to ctime’s format
make_col formatted:format_time(@."Valid From", 'MM/DD/YYYY HH12:MI:SS')
Format the “Valid From” column using US’s date format and a 12-hour clock.
make_col formatted:format_time(@."Valid From", 'YYYY-MM-DD"T"HH24:MI:SSTZH:TZM', "America/Los_Angeles")
Format the “Valid From” column according to ISO 8601, in the America/Los_Angeles timezone.