sqloracledatetimestampto-date

Can TO_DATE function return a TIMESTAMP?


Can, in any form, to_date function return a timestamp?

Example :

I have the following input: '2019-05-31 13:15:25.000000000'

I want to have '2019-05-31 13:15:25' as a result using to_date and not to_timestamp.

I tried :

select to_date(
               substr('2019-05-31 13:15:25.000000000', 1, 19), 
                      'YYYY-MM-DD HH24:MI:SS'
              ) 
  from dual;

But it returns:

31/05/2019

Solution

  • to_date returns a date. If you need a timestamp, you should use to_timestamp.