I'm trying to create a function that will calculate the elapsed time between two date/time variables (i.e. 04/30/01 5:32 PM to 05/01/01 5:32 AM.) The result I'm looking for is to have the #of days, hours and minutes displayed. I've tried a few methods but they're not exactly what I'm looking for. Do you have any suggestions for the best way to do this?
The secret to this kind of function is to extract the elapsed time at the lowest level of detail (or lower) than you need to report it. In your case, you need to report to the nearest minute, so you need to compute the difference in minutes at that level or lower. Using some pseudo-code, the algorithm looks like:
elapsed = Delta_Minutes(date1, date2) minutes = elapsed % 60 # elapsed modulo 60 (minutes per hour) hours = (elapsed \ 60) % 24 # elapsed integer divided by 60 (hours) modulo 24 (hours per day) days = (elapsed \ 1440) # elapsed integer divided by 1440
For More Information
- What do you think about this answer? E-mail us at editor@searchDatabase.com with your feedback.
- The Best Database Design Web Links: tips, tutorials, scripts, and more.
- Have a Database Design tip to offer your fellow DBA's and developers? The best tips submitted will receive a cool prize--submit your tip today!
- Ask your technical Database Design questions--or help out your peers by answering them--in our live discussion forums.
- Ask the Experts yourself: Our Database Design guru is waiting to answer your toughest questions.
Dig Deeper on Oracle and SQL
Related Q&A from Pat Phelan
Have a question for an expert?
Please add a title for your question
Get answers from a TechTarget expert on whatever's puzzling you.