Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Which function to convert "983898064" to a time? 1

Status
Not open for further replies.

hallux

Programmer
Feb 25, 2003
133
US
Hello,
From a table I have been asked to select the time from an integer field and it contains numbers like "983898064". Anybody ideas?

Thanks,
-Hallux
 
Hallux,

That number is "Universal Time Coordinated" (UTC) time. It represents the number of seconds since January 1, 1970. Following are two functions for you that go either direction, (UTC to Oracle) and (Oracle to UTC), followed by examples using your data:
Code:
create or replace function utc_to_oracle (utc_in in number) return date is
begin
	return to_date('01.01.70','dd.mm.rr')+(utc_in/(60*60*24));
end;
/

create or replace function utc_from_oracle (date_in in date) return number is
begin
	return (date_in-to_date('01.01.70','dd.mm.rr'))*(60*60*24);
end;
/

SQL> col a heading "Hallux's UTC|to Oracle" format a20
SQL> select to_char(utc_to_oracle(983898064),'yyyy-mm-dd hh24:mi:ss') a from dual;

Hallux's UTC
to Oracle
--------------------
2001-03-06 17:01:04

SQL> col b heading "Hallux's|Date to|UTC" format 999999999
SQL> select utc_from_oracle(to_date('2001-03-06 17:01:04','yyyy-mm-dd hh24:mi:ss')) b from dual;

  Hallux's
   Date to
       UTC
----------
 983898064
SQL>
Let me know if this is what you wanted.

[santa]Mufasa
(aka Dave of Sandy, Utah, USA @ 01:19 (13Feb04) UTC (aka "GMT" and "Zulu"), 18:19 (12Feb04) Mountain Time)
 
Wow!
Thanks alot for the detailed response.
FYI: I'm located in WVC.
-Hallux
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top