I have 400 records to process and they are in the following formats (string):
3h
24h20min
3h
2d
26min
1h12min
17h35min
6h12min
30s
How do I make a formula that would automatically detect the d
, h
, min
and s
and convert into the right hh:mm:ss
with hh being eventually higher than 24?
This previous answer of mine will get you part of the way.
A slight adjustment is:
And then format the cell as
[h]:mm:ss
, where[h]
means allowing numbers of hours greater than 24 (rather than wrapping around to zero).I am not claiming that this formula will work on all your cases. In fact, it fails when you have minutes alone, seconds alone, days and minutes but no hours, etc. But, you ask for "help or clues", and this should indeed give you a starting point for devising a formula that is appropriate for your circumstances.
EDIT Arrrrrhhhh, I couldn't resist. I made a VBA user-defined function that parses your date strings. It is quite robust and works for all your examples and more -- even string with random characters thrown in, e.g.
6d 243min + 7s
. Note that you still have to format the cells as[h]:mm:ss
.Example: 7 weeks 31 days 24 hours 60 minutes
Formula:
This formula works for all your examples
=SUM(MID(0&A1&"0000",FIND({"s","m","h","d"},0&A1&"xxsmhd")-2,2)/{86400,1440,24,1})
assuming data in cell A1, format result cell as [h]:mm:ss
It fails if you have a single digit value that isn't at the start, so if you have
12h03min
that will be OK but if you have12h3min
the formula will fail. I can probably fix that, though......