Q
Problem solve Get help with specific problems with your technologies, process and projects.

Function for calculating elapsed time between two dates/time variables

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


Dig Deeper on Oracle and SQL

Have a question for an expert?

Please add a title for your question

Get answers from a TechTarget expert on whatever's puzzling you.

You will be able to add details on the next page.

Start the conversation

Send me notifications when other members comment.

Please create a username to comment.

-ADS BY GOOGLE

SearchDataManagement

SearchBusinessAnalytics

SearchSAP

SearchSQLServer

TheServerSide.com

SearchDataCenter

SearchContentManagement

SearchHRSoftware

Close