SQL tutorial | Interview questions | Oracle
Would you like to react to this message? Create an account in a few clicks or log in to continue.

How To Convert Characters to Dates?

Go down

How To Convert Characters to Dates? Empty How To Convert Characters to Dates?

Post by Micheal Sat Jan 16, 2010 9:20 pm

You can convert dates to characters using the TO_DATE() function as shown in the following
examples:
SELECT TO_DATE('07-MAY-2006', 'DD-MON-YYYY') FROM DUAL;
07-MAY-06
SELECT TO_DATE('2006/05/07 ', 'YYYY/MM/DD') FROM DUAL;
07-MAY-06
SELECT TO_DATE('MAY 07, 2006', 'MONTH DD, YYYY') FROM DUAL;
07-MAY-06
SELECT TO_DATE('May 7, 2006', 'fmMONTH DD, YYYY') FROM DUAL;
07-MAY-06
SELECT TO_DATE('SUNDAY, MAY 7, 2006', 'fmDAY, MONTH DD, YYYY') FROM DUAL;
07-MAY-06
How To Convert Times to Characters?
You can convert dates to characters using the TO_CHAR() function as shown in the following
examples:
SELECT TO_CHAR(SYSDATE, 'HH:MI:SS') FROM DUAL;
04:49:49
SELECT TO_CHAR(SYSDATE, 'HH24:MI:SS.FF') FROM DUAL;
-- Error: SYSDATE has no fractional seconds
SELECT TO_CHAR(SYSTIMESTAMP, 'HH24:MI:SS.FF9') FROM DUAL;
16:52:57.847000000
SELECT TO_CHAR(SYSDATE, 'SSSSS') FROM DUAL;
-- Seconds past midnight
69520

Micheal
Admin

Posts : 243
Join date : 2010-01-10

http://sql-tutorial.co.cc

Back to top Go down

Back to top

- Similar topics

 
Permissions in this forum:
You cannot reply to topics in this forum