How to convert date to timestamp(DD-MON-YYYY HH24:

2019-02-18 06:20发布

问题:

I tried below query but its not working

select 
    TO_TIMESTAMP(ColumnName(Data type Date), 'DD-MON-YYYYHH24:MI:SS.FF') 
from TableName 
where Changedate>='01-Dec-2015'

*I need the result without AM/PM indication. Result will be 15-DEC-2015 15:16:42.045016

回答1:

If I got your question right you need the output in the mentioned Format. That would be a conversion to character

select to_char(cast(sysdate as timestamp),'DD-MON-YYYY HH24:MI:SS.FF') from dual

Of course in the above the FF would also always be 000000

But if you have a timestamp variable you would not cast

select to_char(systimestamp,'DD-MON-YYYY HH24:MI:SS.FF') from dual


回答2:

select to_char(cast(sysdate as timestamp),'DD-MON-YYYY HH24:MI:SS') from dual


回答3:

I think you need not have to convert to timestamp if your column is of date data type. Also there is no need to use .FF as date will not have time in milliseconds.

select to_char(ColumnName(Data type Date), 'DD-MON-YYYYHH24:MI:SS.FF') from dual;