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.
Simple date addition doesn’t work with timestamps, at least if you need to preserve the fractional seconds. When you do
to_timestamp('1899-12-30','yyyy-mm-dd')+ date1(in a comment on Mark’s answer) theTIMESTAMPis implicitly converted to aDATEbefore the addition, to the overall answer is aDATE, and so doesn’t have any fractional seconds; then you useto_char(..., '... .FF')it complains with ORA-01821.You need to convert the number of days held by your
date1column into an interval. Fortunately Oracle provides a function to do exactly that,NUMTODSINTERVAL:You can then display that in your desired format, e.g. (using a CTE to provide your
date1value):Or to restrict to thousandths of a second:
An epoch of
1899-12-30sounds odd though, and doesn’t correspond to Excel as you stated. It seems more likely that your expected result is wrong and it should be 2010-04-18, so I’d check your assumptions. Andrew also makes some good points, and you should be storing your value in the table in aTIMESTAMPcolumn. If you receive data like this though, you still need something along these lines to convert it for storage at some point.