
Originally Posted by
joeu2004
There is so much misdirection in this thread, it is difficult to know where to begin.
1. There is nothing wrong with your formula in column D. But it can be greatly simplified.
Change
=INT(B2-A2)&" "&HOUR(MOD(B2-A2,1))&":"&MINUTE(MOD(B2-A2,1))&":"&SECOND(MOD(B2-A2,1))
to
=INT(B2-A2)&" "&HOUR(B2-A2)&":"&MINUTE(B2-A2)&":"&SECOND(B2-A2)
The use of MOD(...,1) is redundant. It extracts the time portion (decimal fraction). That is unnecessary, since HOUR, MINUTE and SECOND look only at the decimal fraction. The integer portion is number of days.
2. The complex numeric format in column D can be removed, since the formula returns text. Change the format to General.
3. The "dd" format specifier cannot display more than 31 because it is day of the month, not number of days.
Date and elapsed time (days, hours, etc) look the same to Excel. For both, the integer part is days; the decimal fraction is time. For a date, the integer part is days since 12/31/1899 (which Excel displays as 1/0/1900, which is not a date after all). So if the elapsed time (B2-A2) is 32 days and some hours, minutes etc, "dd" sees 32 as 32 days after 12/31/1899, which is Feb 1. Consequently, "dd" displays 1.
Given that limitation, the text formula that you have in column D is indeed the only way to display number of days in elapsed time. That is, if you insist on displaying days, hours, minutes and seconds.
On the other hand, if you want numeric elapsed time, you can use the format Custom [h]:mm:ss. That displays 24 and more hours as hours, minutes and seconds.
4. By coincidence, the average calculated in F2 is right for the values in column C, despite the format "dd hh:mm:ss" (without quotes).
But again, the numeric format "dd hh:mm:ss" is risky. It will not work if the average is more than 32 or more days.
Given all of that, it is unclear what direction you want to go.
You could retain both column C (numeric elapsed time) and column D (text presentation of elapsed days, hours etc), and use column C for numeric calculations like the average in F2, as you did.
Alternatively, you could calculate the numeric average in F2 using only column D as follows:
=SUMPRODUCT(LEFT(D2:D20,FIND(" ",D2:D20)-1) + MID(D2:D20,FIND(" ",D2:D20)+1,99)) / ROWS(D2:D20)
Note: That assumes there are no cells in the range that appear blank. Is that a good assumption?
In either case, you still need to decide how to display the average.
Again, the simplest answer is to display numeric time as hours, minutes etc using the format Custom [h]:mm:ss.
Alternatively, you can display text elapsed time as days, hourse etc using the following formula in G2 (formatted as General):
=INT(F2)&" "&HOUR(F2)&":"&MINUTE(F2)&":"&SECOND(F2)
Bookmarks