Purpose
This function converts a character value of the CHAR, VARCHAR, NCHAR, or NVARCHAR2 data type to a value of the DATE data type.
Syntax
TO_DATE(char [, fmt [, 'nlsparam' ] ])
Parameters
Parameter |
Description |
|---|---|
| char | A value of the CHAR, VARCHAR, NCHAR, or NVARCHAR2 data type. |
| fmt | The time format of char. This parameter is optional. If you omit fmt, char must be in the default date format. The default date format is implicitly specified by the nls_territory initialization parameter or explicitly specified by the nls_date_format parameter. |
| nlsparam | The language of the text string to be converted to a date. This parameter is optional. |
Return type
DATE
Examples
Convert the strings 202111, 2021.11.11, and 2021-11-11 11:11:11 to values of the DATE data type.
obclient> SELECT TO_DATE('202111','YYYYMM'),
TO_DATE('2021.11.11','YYYY.MM.DD'),
TO_DATE('2021-11-11 11:11:11','YYYY-MM-DD HH24:MI:SS')
FROM DUAL;
+----------------------------+------------------------------------+------------------------------------------------------+
| TO_DATE('202111','YYYYMM') | TO_DATE('2021.11.11','YYYY.MM.DD') | TO_DATE('2021-11-1111:11:11','YYYY-MM-DDHH24:MI:SS') |
+----------------------------+------------------------------------+------------------------------------------------------+
| 01-NOV-21 | 11-NOV-21 | 11-NOV-21 |
+----------------------------+------------------------------------+------------------------------------------------------+
1 row in set
