How to convert date to timestamp(DD-MON-YYYY HH24:MI:SS.FF format) in oracle?
Asked Answered
M

4

8

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

Manakin answered 17/12, 2015 at 8:4 Comment(2)
Have you tried to_char?Mcdevitt
cast (column as timestamp)??Benighted
P
8

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
Pell answered 17/12, 2015 at 8:34 Comment(0)
W
1
select to_char(cast(sysdate as timestamp),'DD-MON-YYYY HH24:MI:SS') from dual
Worsley answered 17/12, 2015 at 8:38 Comment(0)
T
0

These are 2 ways you can try:

to_char(cast(sysdate as timestamp), 'YYYY-MM-DD HH:MM:SS.ff') 

or:

to_char(to_Date(sysdate, 'DD-MON-YY'), 'YYYY-MM-DD HH:MM:SS') 
Turntable answered 21/5, 2020 at 18:36 Comment(0)
J
-1

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;
Jenaejenda answered 17/12, 2015 at 8:35 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.