Solved

Oracle Arithmatic with Date

Posted on 2011-03-22
3
354 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
[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
  • 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 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 77

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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Have you ever had to make fundamental changes to a table in Oracle, but haven't been able to get any downtime?  I'm talking things like: * Dropping columns * Shrinking allocated space * Removing chained blocks and restoring the PCTFREE * Re-or…
Using SQL Scripts we can save all the SQL queries as files that we use very frequently on our database later point of time. This is one of the feature present under SQL Workshop in Oracle Application Express.
This video shows syntax for various backup options while discussing how the different basic backup types work.  It explains how to take full backups, incremental level 0 backups, incremental level 1 backups in both differential and cumulative mode a…
This video shows how to Export data from an Oracle database using the Original Export Utility.  The corresponding Import utility, which works the same way is referenced, but not demonstrated.
Suggested Courses

626 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