Solved

Convert seconds to a date in oracle plsql

Posted on 2004-08-05
6
608 Views
Last Modified: 2012-06-22
I have a database feild that is stored in seconds from epoch. Is there a simple way to convert this date to a date or timestamp datatype.
0
Comment
Question by:CodeMachine
6 Comments
 
LVL 15

Accepted Solution

by:
jdlambert1 earned 64 total points
ID: 11731829
I don't know of a simple way. Unless someone knows of a PL/SQL function for this, I'd create a stored procedure. Use variables and basic math to turn the seconds into years, months, days, hours, & seconds, then add those to the epoch and output the result.

(Next time you have a PL/SQL question, you'll probably get more responses by posting in the Oracle group instead of the generic database group.)
0
 
LVL 10

Assisted Solution

by:winzig
winzig earned 62 total points
ID: 11732152
Probably folloving formula may help
F_StartTime / (24 * 60 * 60) + 25569)

This code converts ORacle date( no of second from 1.1.1970) to microsoft date (days from 1.1.1900) and then you can use Buid In OS function which convert this no to DATE. (just retype this number to date)
0
 
LVL 15

Assisted Solution

by:ishando
ishando earned 62 total points
ID: 11732534
If EPOCH is a date constant containing the start date of the epoch, e.g 1970-01-01 00:00:00, and utime is a variable containing the number of seconds from the epoch, then the date can be calculated using:

  select to_date(to_char(EPOCH, 'j') + floor(utime/86400), 'j')    /* gets date part of date */
           + (utime/86400 - floor(utime/86400))                          /* the time part */
  from dual;

0
 
LVL 4

Assisted Solution

by:ramumorla
ramumorla earned 62 total points
ID: 11736826
select
        Days,
        A,
        TRUNC(A*24)                                     Hours,
        TRUNC(A*24*60 - 60*TRUNC(A*24))                 Minutes,
        TRUNC(A*24*60*60 - 60*TRUNC(A*24*60))           Seconds,
        TRUNC(A*24*60*60*100 - 100*TRUNC(A*24*60*60))   mSeconds
from
(
select
        trunc(&DIF)             Days,

        &Dif - trunc(&DIF)      A
from dual
)
;
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article describes some very basic things about SQL Server filegroups.
Read about achieving the basic levels of HRIS security in the workplace.
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

740 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question