How to convert date to datetime in Oracle?

Joel Patrick Ndzie picture Joel Patrick Ndzie · Nov 25, 2015 · Viewed 68.9k times · Source

i have a date in oracle with this format DD-MM-YYY and i want to convert it to datetime with this other format DD-MM-YYY HH24:MI how can i proceed?

I've tried this but nothing is working :

to_date(the_date,'DD-MM-YYY HH24:MI')

and also this:

to_date(to_char(date_debut_p),'DD-MM-YYY HH24:MI')

Answer

Lalit Kumar B picture Lalit Kumar B · Nov 25, 2015

i have a date in oracle with this format DD-MM-YYY and i want to convert it to datetime with this other format DD-MM-YYY HH24:MI

No, you are confused. Oracle does not store dates in the format you see. It is internally stored in 7 bytes with each byte storing different components of the datetime value.

DATE data type always has both date and time elements up to a precision of seconds.

If you want to display, use TO_CHAR with proper FORMAT MODEL.

For example,

SQL> select to_char(sysdate, 'mm/dd/yyyy hh24:mi:ss') from dual;

TO_CHAR(SYSDATE,'MM
-------------------
11/25/2015 22:25:42