Change exported dates to values and calculate average

NewOrderFac33

Well-known Member
Joined
Sep 26, 2011
Messages
1,283
Office Version
  1. 2016
  2. 2010
Platform
  1. Windows
Good afternoon,

I have exported data which contains a column showing durations in the following (text) format:

1d 3h 50m 32s
0d 0h 0m 47s
0d 1h 10m 46s
0d 1h 39m 50s
0d 0h 0m 43s
0d 0h 9m 29s
0d 0h 41m 27s

I would like to be able convert these labels into time values, in order to calculate the average for the column - can anyone suggest how I might be ale to accomplish that, please?

Thanks - Pete
 

Excel Facts

Difference between two dates
Secret function! Use =DATEDIF(A2,B2,"Y")&" years"&=DATEDIF(A2,B2,"YM")&" months"&=DATEDIF(A2,B2,"MD")&" days"
Try:
Book1
ABC
1StringDays[h]:mm:ss
21d 3h 50m 32s1.16027:50:32
30d 13h 0m 47s0.54213:00:47
40d 1h 10m 46s0.0491:10:46
50d 1h 39m 50s0.0691:39:50
60d 0h 0m 43s0.0000:00:43
70d 0h 9m 29s0.0070:09:29
80d 0h 41m 27s0.0290:41:27
9Average0.2656:21:56
Sheet1
Cell Formulas
RangeFormula
B2:B8B2=--LEFT(A2,FIND("d",A2)-1)+MID(A2,FIND("h",A2)-2,2)/24+MID(A2,FIND("m",A2)-2,2)/1440+MID(A2,FIND("s",A2)-2,2)/86400
C2:C8C2=--LEFT(A2,FIND("d",A2)-1)+MID(A2,FIND("h",A2)-2,2)/24+MID(A2,FIND("m",A2)-2,2)/1440+MID(A2,FIND("s",A2)-2,2)/86400
B9:C9B9=AVERAGE(B2:B8)
 
Upvote 0
Solution
Absolutely spot on - thank you VERY much! :)
Mostly working, but I seem to be getting errors for anything that goes over a month thus:

45d 1h 27m 44s14 days 01 hrs 27 m 44 s
42d 7h 26m 33s11 days 07 hrs 26 m 33 s
45d 7h 23m 30s14 days 07 hrs 23 m 30 s
20d 7h 22m 14s20 days 07 hrs 22 m 14 s

The top three have 31 days subtracted from them, whereas the bottom one is correct (all use your formula) - any thoughts? Thanks :)
 
Upvote 0
I don't understand what you're showing me. Your left column works fine as it matches the same structure as the sample provided in the OP. Since it's a number, I can subtract it from 31. Where did the right column come from?
Book1
ABCD
1Time StringDaysDays -31
245d 1h 27m 44s45.0609314.06093
342d 7h 26m 33s42.3101011.31010
445d 7h 23m 30s45.3079914.30799
520d 7h 22m 14s20.30711-10.69289<- don't have enough 31 days, what do you expect in this case?
6
714 days 01 hrs 27 m 44 s#VALUE!<- not in the same format #d #h #m #s
811 days 07 hrs 26 m 33 s#VALUE!<- not in the same format #d #h #m #s
914 days 07 hrs 23 m 30 s#VALUE!<- not in the same format #d #h #m #s
1020 days 07 hrs 22 m 14 s#VALUE!<- not in the same format #d #h #m #s
Sheet2
Cell Formulas
RangeFormula
B2:B5,B7:B10B2=--LEFT(A2,FIND("d",A2)-1)+MID(A2,FIND("h",A2)-2,2)/24+MID(A2,FIND("m",A2)-2,2)/1440+MID(A2,FIND("s",A2)-2,2)/86400
C2:C5C2=B2-31
 
Upvote 0
The left column contains strings, the right column shows the values that your formula returns. So, it works OK day-wise as long as the number of days in the string is less than 31 (the fourth value in the list), but if the number of days in the string exceeds 31, 31 days are subtracted from the "Day" part of the result e.g. 45 returns 14, 42 returns 11 and so on

45d 1h 27m 44s14 days 01 hrs 27 m 44 s
42d 7h 26m 33s11 days 07 hrs 26 m 33 s
45d 7h 23m 30s14 days 07 hrs 23 m 30 s
20d 7h 22m 14s20 days 07 hrs 22 m 14 s
 
Upvote 0
EDIT:
I believe this because the dd formatting is limited to days of the month for 31 days even though the underlying number is correct. You might have to split it up into 2 cells to show the day and time separately.
 
Last edited:
Upvote 0
N.B. My system has Regional Settings of dd-mmm-yy; but I do not see why this makes a difference.

The results show the correct number of days; the "d" part just yields a number.
I do not see why the formula is showing 14 instead of 45.

Dates and Time 2024.xlsm
ABCD
1Excel 365
2Time StringTotal
345d 1h 27m 44s45.06092645.060925945.0609259
442d 7h 26m 33s42.31010442.310104242.3101042
545d 7h 23m 30s45.30798645.307986145.3079861
620d 7h 22m 14s20.30710620.307106520.3071065
7
850d 1h50.041666750.0416667
4g
Cell Formulas
RangeFormula
B3:B6B3=LEFT(A3,FIND("d",A3)-1)+MID(A3,FIND("h",A3)-2,2)/24+MID(A3,FIND("m",A3)-2,2)/1440+MID(A3,FIND("s",A3)-2,2)/86400
C3:C6C3=TEXTBEFORE(A3,"d")+RIGHT(TEXTBEFORE(A3,"h"),2)/24+RIGHT(TEXTBEFORE(A3,"m"),2)/(24*60)+RIGHT(TEXTBEFORE(A3,"s"),2)/(24*60*60)
D3:D6D3=TEXTBEFORE(A3,"d")+TEXTJOIN(":",,TEXTSPLIT(TEXTAFTER(A3,"d "),{"h ","m ","s"}))
B8B8=LEFT(A8,FIND("d",A8)-1)+MID(A8,FIND("h",A8)-2,2)/24
C8C8=TEXTBEFORE(A8,"d")+RIGHT(TEXTBEFORE(A8,"h"),2)/24
 
Last edited:
Upvote 0

Forum statistics

Threads
1,221,526
Messages
6,160,340
Members
451,637
Latest member
hvp2262

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top