Solved

Oracle Arithmatic with Date

Posted on 2011-03-22
3
340 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 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: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

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

Working with Network Access Control Lists in Oracle 11g (part 2) Part 1: http://www.e-e.com/A_8429.html Previously, I introduced the basics of network ACL's including how to create, delete and modify entries to allow and deny access.  For many…
Configuring and using Oracle Database Gateway for ODBC Introduction First, a brief summary of what a Database Gateway is.  A Gateway is a set of driver agents and configurations that allow an Oracle database to communicate with other platforms…
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
Via a live example, show how to restore a database from backup after a simulated disk failure using RMAN.

828 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