Solved

Convert seconds to a date in oracle plsql

Posted on 2004-08-05
6
584 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

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

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

Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
SQL Command Tool comes with APEX under SQL Workshop. It helps us to make changes on the database directly using a graphical user interface. This helps us writing any SQL/ PLSQL queries and execute it on the database and we can create any database ob…
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…

770 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