AdBlock Detected!
Our website is made possible by displaying ads to our visitors. Please supporting us by whitelisting our website.
SQL TO_DATE Function |
SQL > SQL String Functions >
TO_DATE Function
The TO_DATE function is used in Oracle to convert a string to a date. SyntaxThe syntax of this function is as follows: TO_DATE ( String, [Format], [NLS Setting] )
The most important parameter is [Format]. Valid [Format] values are as follows:
[NLS Setting] is used to change the output format based on the NLS Territoy and NLS Language (NLS stands for National Language Support). It is optional and is rarely used. ExamplesBelow are some examples on using the TO_DATE function. For clarity, the results are expressed in the 'YYYY MM DD HH24:MI:SS' format (Year Month Date Hour:Minute:Second, where Hour has a value between 0 and 23): Example 1SELECT TO_DATE('20100105', 'YYYYMMDD') FROM DUAL;
Result: 2010 01 05 00:00:00
Example 2SELECT TO_DATE('1999-JAN-05', 'YYYY-MON-DD') FROM DUAL;
Result: 1999 01 05 00:00:00
Example 3SELECT TO_DATE('2005-12-12 03600', 'YYYY-MM-DD SSSSS') FROM DUAL;
Result: 2005 12 12 01:00:00
3600 seconds equals to 1 hour. Example 4SELECT TO_DATE('2005 120 05400', 'YYYY DDD SSSSS') FROM DUAL;
Result: 2005 04 30 01:30:00
April 30th is the 120th day in 2005. 5400 seconds equals to 1 hour and 30 minutes. Example 5SELECT TO_DATE('99-JAN-05', 'YY-MON-DD') FROM DUAL;
Result: 2099 01 05 00:00:00
The 'YY' format converts the year to the current century. Example 6SELECT TO_DATE('99-JAN-05', 'RR-MON-DD') FROM DUAL;
Result: 1999 01 05 00:00:00
The 'RR' logic converts '99' to the previous century, hence the result is 1999. |
Our website is made possible by displaying ads to our visitors. Please supporting us by whitelisting our website.