Solved

Convert seconds to a date in oracle plsql

Posted on 2004-08-05
6
615 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

This article shows the steps required to install WordPress on Azure. Web Apps, Mobile Apps, API Apps, or Functions, in Azure all these run in an App Service plan. WordPress is no exception and requires an App Service Plan and Database to install
A Stored Procedure in Microsoft SQL Server is a powerful feature that it can be used to execute the Data Manipulation Language (DML) or Data Definition Language (DDL). Depending on business requirements, a single Stored Procedure can return differe…
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…

734 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