TO_CHAR
Converts a DATE
, DATETIME
, DATETIME(6)
, TIME
, TIMESTAMP
or TIMESTAMP(6)
value to a string.
Syntax
TO_CHAR ( convert_from_value, result_format )
Arguments
convert_from_value: Value of one of the following data types:
DATE
,DATETIME
,DATETIME(6)
,TIME
,TIMESTAMP
orTIMESTAMP(6)
.result_format: A format string, comprised of one or more of the format specifiers listed in the table below:
Format Specifiers
Meaning | Format Specifier |
---|---|
Four digit year |
|
Two digit year |
|
Two digit year (20th century for 00-49) |
|
Three letter month (Jan - Dec) |
|
Month (January - December) |
|
Month as a digit (1 - 12) |
|
Day of the week as a digit (1 - 7) |
|
Three letter day (Sun - Sat) |
|
Day (1 - 31) |
|
Hour (0 - 23) |
|
Hour (1 - 12) |
|
Minute (0 - 59) |
|
Second (0 - 59) |
|
Precision for seconds |
|
AM or PM |
|
Important
TO_CHAR
’s format string may contain characters that are not format specifiers. These characters appear as literals in the resulting string.
Examples
The following examples use the :>
operator to cast a string to a DATE
, TIMESTAMP
, or similar type. TO_CHAR
then converts the casted type to a string.
Call to | Result |
---|---|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Important
When you call TO_CHAR
and don’t explicitly type-cast the first argument, TO_CHAR
will implicitly type-cast the first argument to TIMESTAMP(6)
.
When you call TO_CHAR
and specify a temporal-type column in the first argument, no typecast is needed.