Qlik Community

QlikView Scripting

Discussion Board for collaboration on QlikView Scripting.

Highlighted
bdunsmoor
New Contributor III

Convert ISO 8601 duration string to seconds

I'm loading data that is formatted as ISO 8601 duration string.  Below are some samples from the data set. 

Each string always starts with "P," which designates Period, and "T" which designates Time.  The rest of the string  may contain H (Hours), M (Minutes) or S (Seconds) along with numbers for each time element.  

For example, the string "PT1H3M11.312S" represents 1 hour, 3 minutes, 11.312 seconds, which translates to 3791 seconds.  

Question: is there a script function that will convert an ISO 8601 duration string to seconds?  

I'm hoping there is a function so that I won't have to parse out the time elements individually.

Samples from my data:

inboundTalkTime
PT0S
PT1H3M11.312S
PT1H10M21.892S
PT1H15M56.944S
PT1H20M7.027S
PT1H39M18.652S
PT1H49M33.105S
PT18M15.285S
PT42M38.344S
PT54M0.343S
1 Solution

Accepted Solutions
MVP
MVP

Re: Convert ISO 8601 duration string to seconds

If you need to reuse the expression it would be better defined as a variable-that-takes-parameters (function):

Annotation 2019-07-18 084455.jpg

Annotation 2019-07-18 084526.jpg

3 Replies
MVP
MVP

Re: Convert ISO 8601 duration string to seconds

I can't give you a single function - but maybe a single expression might do the trick:

Annotation 2019-07-18 083745.jpg

MVP
MVP

Re: Convert ISO 8601 duration string to seconds

If you need to reuse the expression it would be better defined as a variable-that-takes-parameters (function):

Annotation 2019-07-18 084455.jpg

Annotation 2019-07-18 084526.jpg

bdunsmoor
New Contributor III

Re: Convert ISO 8601 duration string to seconds

Thank you Peter.  That's worked perfectly.