Solved

Oracle Arithmatic with Date

Posted on 2011-03-22
3
327 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 73

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 73

Accepted Solution

by:
sdstuber earned 500 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 76

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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Join & Write a Comment

I remember the day when someone asked me to create a user for an application developement. The user should be able to create views and materialized views and, so, I used the following syntax: (CODE) This way, I guessed, I would ensure that use…
From implementing a password expiration date, to datatype conversions and file export options, these are some useful settings I've found in Jasper Server.
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.

758 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

22 Experts available now in Live!

Get 1:1 Help Now