PL/SQL (MOSC)

MOSC Banner

converting dates to and from fractional julian dates are *sometimes* off by a second...

edited Apr 20, 2012 7:51AM in PL/SQL (MOSC) 5 commentsAnswered
I'm dealing with an application that stores dates as fractional julian dates, eg "2456037.426632" for "2012-04-19 10:14:21"

Since Oracle only works with integer Julian dates, I"ve developed a pair of functions to convert back and forth:

CREATE OR REPLACE FUNCTION "CALENDAR3"."DATE_TO_FRACTJULIAN"
(date_in IN DATE) return NUMBER is Fjdate number;
begin
select round((to_number((to_char(date_in, 'J')),'9999999') + to_number((to_char(date_in,'SSSSS')),'99999')/86400),6) into Fjdate from dual;
return (Fjdate);
end;

and 

CREATE OR REPLACE FUNCTION "CALENDAR3"."FRACTJULIAN_TO_DATE"
(fjdate_in IN NUMBER) return DATE is Fj2date date;

Howdy, Stranger!

Log In

To view full details, sign in to My Oracle Support Community.

Register

Don't have a My Oracle Support Community account? Click here to get started.

Category Leaderboard

Top contributors this month

New to My Oracle Support Community? Visit our Welcome Center

MOSC Help Center