Excel Formula: Calculate Days Hours Minutes seconds between Two Dates
General in Excel, we use formulas to count the difference between two dates in days or difference between two times. However, in some special cases, we may want to get the days, hours, minutes, and seconds between two datetimes, this tutorial introduces the formula to solve this job.
|INT(end_datetime-start_datetime)&" days "&TEXT(end_datetime-start_datetime,"h"" hrs ""m"" mins ""s"" secs""")|
|End_datetime, start_datetime: the two dates that you to calculate the difference between.|
If the argument end_datetime is smaller than the argument start_datetime, the formula will return the error value #VALUE!.
This formula returns a text value.
How this formula work
To get the difference between two datetimes in cell B3 and cell C3, please use below formula:
|=INT(C3-B3)&" days "&TEXT(C3-B3,"h"" hrs ""m"" mins ""s"" secs""")|
Press Enter key to get the result.
INT function: The INT function returns the integer part of a decimal number.
As the date is stored as serial whole number in Excel, and the time is stored as serial decimal number which is less than 1 in Excel, and the datetime is stored as a serial decimal number, for instance, the datetime 12/1/2019 13:23:11 is stored as 43800.5577662037 in Excel. Here the INT function extracts the whole number part of the difference between two datetimes to get the difference in days.
TEXT function: This function is used to convert number to text with a specified format.
&: This is a connector that connects the results of each part in the formula.
Tip: To get the total days, hours, minutes, and seconds between a set of start and end dates, you can adapt the formula using SUMPRODUCT function:
=INT(SUMPRODUCT(ends-starts))&" days "&TEXT(SUMPRODUCT(ends-starts),"h"" hrs ""m"" mins """)
The argument ends is the range of end dates, the starts is the cell range of start dates, for example, range C3:C5 contains the end dates, B3:B5 contains the start dates, please using the formula like this:
=INT(SUMPRODUCT(C3:C5-B3:B5))&" days "&TEXT(SUMPRODUCT(C3:C5-B3:B5),"h"" hrs ""m"" mins """)
Press Enter key.
- Calculate days remaining in month
In this tutorial, it provides a formula to quickly calculate the days remaining in month in Excel.
- Calculate days remaining from today
Sometimes, you may want to know how many days remaining until expiration from today of each food product. In Excel, there is a formula that can help you to quickly get the remaining days.
- Calculate Days Remaining Between Two Dates
Here, this tutorial provides a formula to quickly calculate the left days between two dates.
- Calculate Network Time With Break In A Timesheet
It provides the formula which uses the MOD function to calculate the network time with breaks in Excel.
- Excel IF Function
Test for specified conditions, then returns the corresponding values
- Excel VALUE Function
Convert text to number.
- Excel MONTH Function
The MONTH is used to get the month as integer number (1 to 12) from date.
- Excel DAY Function
DAY function gets the day as a number (1 to 31) from a date
- Excel YEAR Function
The YEAR function returns the year based on the given date in a 4-digit serial number format.