Date Functions: To_Char

Description: Converts DATE and TIMESTAMP to VARCHAR2 with the specified format.

TO_DATE(<date_string>, <format mask>, <nls_PARAMETER>)
 
SELECT TO_CHAR(datecol1, 'DAY-MONTH-YY') COL1,
TO_CHAR(datecol2, 'D-MM/YYYY HH24:MI:SS') COL2,
TO_CHAR(datecol2, 'YYYY-MON-DD HH24') COL3
FROM t;
 
--Demo of FM Formatting From Tom Kyte (Oracle Magazine 3-4/2004)
 
    SELECT TO_CHAR(dt, 'HH:MI AM') A,
       TO_CHAR(dt, 'FMHH:MI AM') B,
       TO_CHAR(dt, 'FMHHFM:MI AM') C
FROM (
  SELECT TO_DATE('09:01 am', 'HH:MI AM') dt
  FROM dual);

Enjoyed this post? Share it!

 

Leave a comment

Your email address will not be published.