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```

#### Have a question for an expert?

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.

## SearchDataManagement

• ### Open source database use is a growing trend

Study shows that more users are using open source software for data management, with most organizations using more than one ...

• ### Databricks contributes Delta Lake to the Linux Foundation

Databricks has found a new home at the Linux Foundation for its open source Delta Lake data lake project, in a bid to help grow a...

• ### Apache Rya matures open source triple store database

Open source triple store database technology used by the U.S. Navy moves forward as a stable, mature project at the Apache ...

• ### SAP Tennis Analytics adds tool to track patterns within points

Players and coaches in the Women's Tennis Association are now able to discover the tendencies of their opponents within a given ...

Teradata unveiled Vantage Analyst and Customer experience, two new tools now part of the vendor's analytics platform, on Tuesday ...

• ### SAS analytics platform aided by \$1 billion AI investment

The SAS suite of business intelligence products is quickly seeing results from the vendor's \$1 billion commitment to AI seven ...

## SearchSAP

• ### President of SAP Customer Experience departs

Alex Atzberger is leaving his post as president of SAP Customer Experience. He will be replaced by industry veteran Bob Stutz. ...

New SAP co-CEOs Jennifer Morgan and Christian Klein must clarify SAP's products strategy, explain the experience economy and help...

• ### CEO of SAP Bill McDermott abruptly resigns

Bill McDermott, CEO of longtime ERP, CRM and BI software vendor SAP, resigned Thursday triggering a succession plan that promotes...

## SearchSQLServer

• ### SQL Server database design best practices and tips for DBAs

Good database design is a must to meet processing needs in SQL Server systems. In a webinar, consultant Koen Verbeeck offered ...

• ### SQL Server in Azure database choices and what they offer users

SQL Server databases can be moved to the Azure cloud in several different ways. Here's what you'll get from each of the options ...

• ### Using a LEFT OUTER JOIN vs. RIGHT OUTER JOIN in SQL

In this book excerpt, you'll learn LEFT OUTER JOIN vs. RIGHT OUTER JOIN techniques and find various examples for creating SQL ...

## TheServerSide.com

• ### Is Java slow? Compared to C++, it's faster than you think

If you find that Java is slower than other languages, such as C++, here's how to better compare the two and the major differences...

• ### Java video games, like Minecraft, keep the language popular

The next generation of Java developers can learn the ins and outs of the language through an unlikely source: video games such as...

• ### Pivotal, Microsoft team up to deliver Azure Spring Cloud

Azure Spring Cloud, jointly developed by Microsoft and Pivotal, lets Spring developers bring apps to the cloud without concern ...

## SearchDataCenter

• ### Improve server rack physical security with ISO standards

Safeguarding information access is essential to data center operations. With ISO Standard 27001 and the right locking mechanisms,...

• ### Essential private cloud migration steps

Executive buy-in, application evaluation and tool configuration are all important parts of cloud selection. With these steps, ...

• ### IBM quantum computers' usefulness in sight -- using binoculars

IBM's Bob Sutor discusses Big Blue's new quantum systems and computation center, the realities of quantum computing today and how...

## SearchContentManagement

• ### Alfresco Software acquires SAP connector company Pernexas

The acquisition aims to make gaining new customers easier by providing another option to SAP customers looking for a cloud-native...

• ### 5 tips to avoid content sprawl when using Microsoft Teams

Businesses should heed this advice when rolling out Microsoft Teams to avoid content sprawl and ensure users can easily find the ...

• ### WebPurify launches profanity filter for memes and images

WebPurify has launched a beta of its Optical Character Recognition Profanity Filter Service to identify and block profane images ...

## SearchHRSoftware

• ### A backlash emerges over automated interviewing

Illinois may have adopted the nation's first automated hiring law, which will take effect Jan 1. The law is likely to become a ...

• ### Get smarter about HR data security

HR deals with mountains of sensitive employee data and must do a better job of protecting that information. Here's a look at how ...

• ### Walmart, FedEx make case for VR training

The payback from virtual training may be improved retention and shorter training times. An hour-long training period can be ...

Close