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

x
?
Solved

Oracle Arithmatic with Date

Posted on 2011-03-22
3
Medium Priority
?
365 Views
Last Modified: 2012-05-11
How can i get the total number of hours between two dates using SQL in Oracle.  For example...

 SELECT (to_date('3/28/2011 12:46','mm/dd/yyyy hh24:mi') - to_date('3/28/2011 11:59','mm/dd/yyyy hh24:mi'))   from dual  

returns..'0.0326388888888888888888888888888888888889'

i need to get that into a time which in this case would be 47 minutes.  how can I do that?
0
Comment
Question by:jmpatton
  • 2
3 Comments
 
LVL 74

Expert Comment

by:sdstuber
ID: 35189778
(to_date('3/28/2011 12:46','mm/dd/yyyy hh24:mi') - to_date('3/28/2011 11:59','mm/dd/yyyy hh24:mi'))  * 1440


the 1440 is number of minutes in a day
0
 
LVL 74

Accepted Solution

by:
sdstuber earned 2000 total points
ID: 35189795
if you want the value to be in hours then multiply the result by 24 instead of 1440

that will yield .7833333  hours
0
 
LVL 78

Expert Comment

by:slightwv (䄆 Netminder)
ID: 35189831
If you want the breakdown of hours, minutes and seconds not just one:  There are several links out there on how to do this.

For example, seconds to hours,minutesmseconds:
http://www.adp-gmbh.ch/ora/sql/examples/convert_secs_hh_mi_ss.html

If you can go with the TIMESTAMP data type, the math is a little easier.

Both methods are covered in:
http://www.databasejournal.com/features/oracle/article.php/2234501/A-Comparison-of-Oracles-DATE-and-TIMESTAMP-Datatypes.htm
0

Featured Post

 [eBook] Windows Nano Server

Download this FREE eBook and learn all you need to get started with Windows Nano Server, including deployment options, remote management
and troubleshooting tips and tricks

Question has a verified solution.

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

Cursors in Oracle: A cursor is used to process individual rows returned by database system for a query. In oracle every SQL statement executed by the oracle server has a private area. This area contains information about the SQL statement and the…
Background In several of the companies I have worked for, I noticed that corporate reporting is off loaded from the production database and done mainly on a clone database which needs to be kept up to date daily by various means, be it a logical…
This video shows how to Export data from an Oracle database using the Datapump Export Utility.  The corresponding Datapump Import utility is also discussed and demonstrated.
Via a live example, show how to restore a database from backup after a simulated disk failure using RMAN.
Suggested Courses

772 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