Sql – In Oracle, convert number(5,10) to date

date formatoraclesql

When ececute the following SQL syntax in Oracle, always not success, please help.

40284.3878935185 represents '2010-04-16 09:18:34', with microsecond.

an epoch date of 01 January 1900 (like Excel).

create table temp1 (date1 number2(5,10));

insert into temp1(date1) values('40284.3878935185');

select to_date(date1, 'yyyy-mm-dd hh24:mi:ssxff') from temp1

Error report: SQL Error: ORA-01861: literal does not match format
string
01861. 00000 – "literal does not match format string"
*Cause: Literals in the input must be the same length as literals in
the format string (with the exception of leading whitespace). If the
"FX" modifier has been toggled on, the literal must match exactly,
with no extra whitespace.
*Action: Correct the format string to match the literal.

Thanks to Mark Bannister

Now the SQL syntax is:

select to_char(to_date('1899-12-30','yyyy-mm-dd') + 
date1,'yyyy-mm-dd hh24:mi:ss')  from temp1

but can't fetch the date format like 'yyyy-mm-dd hh24:mi:ss.ff'. Continue look for help.

Best Answer

Using an epoch date of 30 December 1899, try:

select to_date('1899-12-30','yyyy-mm-dd') + date1
Related Topic