Solved

Oracle Arithmatic with Date

Posted on 2011-03-22
3
346 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: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering 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

Suggested Solutions

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…
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 configure and send email from and Oracle database using both UTL_SMTP and UTL_MAIL, as well as comparing UTL_SMTP to a manual SMTP conversation with a mail server.
This video explains what a user managed backup is and shows how to take one, providing a couple of simple example scripts.

751 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