Solved

Convert seconds to a date in oracle plsql

Posted on 2004-08-05
6
562 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

APEX (Application Express) is used to develop a web application from Oracle. SQL Workshop is one of the tools that comes with Oracle APEX to query or modify the database objects or to make any changes to the structure.
Many companies are looking to get out of the datacenter business and to services like Microsoft Azure to provide Infrastructure as a Service (IaaS) solutions for legacy client server workloads, rather than continuing to make capital investments in h…
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…

771 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now