please tell me how to convert the ISO 8601 duration (P2Y3M4DT1H2M1S) format into hours in google sheets, provided that some letters may not be (P1D, PT2H) and so on. Maybe there is a formula in google sheets? Thank you in advance
Tried via chatgpt but without success
I believe I have solution for you, although it is unclear what format you want it in exactly.
Tested with
P3Y6M4DT12H30M5Sreturns108:30:5Breaking this down into sections:
Means if it doesn't match the regular expression it then returns a blank cell.
Extracts all the relevant numbers into an array. Regular Expression taken from here.
Extracts the numbers at those specific positions.
Note, the year and month are not later used as you cannot tell what month or year it is to be accurate.
This simply converts all the relevant values into seconds. If you wish to do some other format, starting with seconds allows you to change it easier.
This converts the seconds into the format of
HH:MM:SSwith hours exceeding 24 allowed, and decimal seconds also permitted.A version that can work on an entire range at once is below:
Just change A1:A6 to the relevant range.