Best way to Convert time stored as text, at different lengths to a standard time unit?

AYouQueTai

Board Regular
Joined
Sep 14, 2019
Messages
50
Office Version
  1. 365
Platform
  1. Windows
Hello,

Wondering how you all would go about this. I have been mucking around with this all afternoon trying to go from LEFT to RIGHT and using LEN to come up with a formula that works for all of the following entries.
How would you standardize this? There are no seconds when there are hours. the minutes go from left to right depending on if there are hours. If there are 1-9 units it is a single digit rather than always having 2, so it moves the hour, minute or second identifier. Is there an easy way to do this?

Book2
AB
1Idling Time(The Goal) Idle Time
25m 8s00:05:08
35m 11s00:05:11
414m 33s00:14:33
51h 2m01:02:00
610h 5m10:05:00
712h 15m12:15:00
Sheet1


Thanks,
 

Excel Facts

Create a Pivot Table on a Map
If your data has zip codes, postal codes, or city names, select the data and use Insert, 3D Map. (Found to right of chart icons).
Try:
Book1
ABC
1Idling Time(The Goal) Idle Time
25m 8s0:05:08<- formatted [h]:mm:ss
35m 11s0:05:11
414m 33s0:14:33
51h 2m1:02:00
610h 5m10:05:00
712h 15m12:15:00
812h 15m 30s12:15:30
Sheet4
Cell Formulas
RangeFormula
B2:B8B2=LET( r,REPLACE(A2,1,0," "), h,TEXTAFTER(TEXTBEFORE(r,"h",,,,0)," ",-1,,,0), m,TEXTAFTER(TEXTBEFORE(r,"m",,,,0)," ",-1,,,0), s,TEXTAFTER(TEXTBEFORE(r,"s",,,,0)," ",-1,,,0), TIME(h,m,s))
 
Upvote 1
Solution
Dates and Time 2024.xlsm
ABC
1Idling Time(The Goal) Idle Time
25m 8s0:05:080:05:08
35m 11s0:05:110:05:11
414m 33s0:14:330:14:33
51h 2m1:02:001:02:00
610h 5m10:05:0010:05:00
712h 15m12:15:0012:15:00
8
3h
Cell Formulas
RangeFormula
C2:C7C2=IF(IFERROR((FIND("h",A2)>0),0),LET(t,TEXTSPLIT(A2,{"h ","m"}),TIME(INDEX(t,1),INDEX(t,2),0)),LET(t,TEXTSPLIT(A2,{"m ","s"}),TIME(0,INDEX(t,1),INDEX(t,2))))
 
Upvote 1
One more.

Book1
AB
1Idling Time(The Goal) Idle Time
25m 8s00:05:08
35m 11s00:05:11
414m 33s00:14:33
51h 2m01:02:00
610h 5m10:05:00
712h 15m12:15:00
Sheet1
Cell Formulas
RangeFormula
B2:B7B2=TIMEVALUE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(IF(IFERROR(FIND("h",A2),0)= 0,"0h" & A2,A2),"h",":"),"m",":"),"s","")," ",""))
 
Upvote 1
Some more (trying to use the new beta Regex functions):
Book1
ABCD
1Idling Time(The Goal) Idle TimeRegex (Beta)Let/Texsplit/Map/Lambda
25m 8s00:05:0800:05:0800:05:08
35m 11s00:05:1100:05:1100:05:11
414m 33s00:14:3300:14:3300:14:33
51h 2m01:02:0001:02:0001:02:00
610h 5m10:05:0010:05:0010:05:00
712h 15m12:15:0012:15:0012:15:00
Sheet1
Cell Formulas
RangeFormula
C2:C7C2=LET(pattern, "((\d+)h)?\s?((\d+)m)?\s?((\d+)s)?\s?", hour, NUMBERVALUE(REGEXREPLACE(A2,pattern,"$2")), min, NUMBERVALUE(REGEXREPLACE(A2,pattern,"$4")), sec, NUMBERVALUE(REGEXREPLACE(A2,pattern,"$6")), TEXT(TIME(hour,min,sec), "hh:mm:ss") )
D2:D7D2=TEXT( SUM( LET(split,TEXTSPLIT(A2," "), MAP(split,LAMBDA(part,LET(s,RIGHT(part,1),n,LEFT(part,LEN(part)-1),IF(s="h",3600*n,IF(s="m",60*n,IF(s="s",1*n)))))) ) )/60/60/24, "hh:mm:ss" )
 
Upvote 1

Forum statistics

Threads
1,223,214
Messages
6,170,772
Members
452,353
Latest member
strainu

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