Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Convert seconds to a date in oracle plsql

Posted on 2004-08-05
6
Medium Priority
?
695 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 256 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 248 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 248 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 248 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

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

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

Microsoft Access is a place to store data within tables and represent this stored data using multiple database objects such as in form of macros, forms, reports, etc. After a MS Access database is created there is need to improve the performance and…
Creating a Cordova application which allow user to save to/load from his Dropbox account the application database.
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Suggested Courses

916 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