TO_DATE
TO_DATE converts a string value to a DATE type.
Syntax
TO_DATE (
expression ,
pattern )
Semantics
Notes
- To use a double quote character in the output, precede it with a double backslash. This is necessary because the backslash already has a special meaning in a string constant. For example:
'\\"YYYY Month\\"'
- TO_TIMESTAMP and TO_DATE skip multiple blank spaces in the input string if the FX option is not used. FX must be specified as the first item in the template. For example TO_TIMESTAMP('2000 JUN', 'YYYY MON') is correct, but TO_TIMESTAMP('2000 JUN', 'FXYYYY MON') returns an error, because TO_TIMESTAMP expects one space only.
- The YYYY conversion from string to TIMESTAMP or DATE has a restriction if you use a year with more than four digits. You must use some non-digit character or template after YYYY, otherwise the year is always interpreted as four digits. For example (with the year 20000): to_date('200001131', 'YYYYMMDD') will be interpreted as a four-digit year; instead use a non-digit separator after the year, like to_date('20000-1131', 'YYYY-MMDD') or to_date('20000Nov31', 'YYYYMonDD').
- In conversions from string to TIMESTAMP or DATE, the CC field is ignored if there is a YYY, YYYY or Y,YYY field. If CC is used with YY or Y then the year is computed as (CC-1)*100+YY.
Examples
TO_DATE('05 Dec 2000', 'DD Mon YYYY')
See Also
Template Pattern Modifiers for Date/Time Formatting