Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

like image 382
Mizanur Rahman Milon Avatar asked Dec 17 '15 08:12

Mizanur Rahman Milon


People also ask

What is FF in TIMESTAMP in Oracle?

FF'. By default format of TIMESTAMP WITH TIME ZONE is 'YYYY-MM-DD HH24: MI: SS. FF TZH: TZM'. Here TZH is Time Zone Hour and TZM is Time Zone Minute. The digits / length of Fraction of Seconds can be specified from 0 – 9 digits.

Can we convert date to TIMESTAMP in Oracle?

Oracle has expanded on the DATE datatype and has given us the TIMESTAMP datatype which stores all the information that the DATE datatype stores, but also includes fractional seconds. If you want to convert a DATE datatype to a TIMESTAMP datatype format, just use the CAST function.


1 Answers

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
like image 122
hol Avatar answered Sep 29 '22 04:09

hol