Important
The SingleStore 9.1 release candidate (RC) gives you the opportunity to preview, evaluate, and provide feedback on new and upcoming features prior to their general availability. In the interim, SingleStore 9.0 is recommended for production workloads, which can later be upgraded to SingleStore 9.1.
TO_ CHAR
On this page
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,TIMESTAMPorTIMESTAMP(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_’s format string may contain characters that are not format specifiers.
Examples
The following examples use the :> operator to cast a string to a DATE, TIMESTAMP, or similar type.TO_ then converts the casted type to a string.
|
Call to |
Result |
|---|---|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Important
When you call TO_ and don’t explicitly type-cast the first argument, TO_ will implicitly type-cast the first argument to TIMESTAMP(6).
When you call TO_ and specify a temporal-type column in the first argument, no typecast is needed.
Last modified: April 24, 2021