TO_DATE()¶
TO_DATE() returns a DATETIME value if the format string contains both date and time parts, or a DATE or TIME value if the string contains only date or time parts.
Description¶
TO_DATE() returns a DATETIME value if the format string contains both date and time parts, or a DATE or TIME value if the string contains only date or time parts.
Syntax¶
> TO_DATE(str,format)
Arguments¶
Arguments |
Description |
|---|---|
str |
Required. |
format |
Required. A format string indicating the format of the return value. |
Note
note
The format string can contain literal characters and format specifiers beginning with %. Literal characters in format must match literally in str. Format specifiers in format must match a date or time part in str.
Examples¶
mysql> SELECT TO_DATE('2022-01-06 10:20:30','%Y-%m-%d %H:%i:%s') as result;
+---------------------+
| result |
+---------------------+
| 2022-01-06 10:20:30 |
+---------------------+
1 row in set (0.00 sec)
Constraints¶
The date type supports only yyyy-mm-dd and yyyymmdd for now.