Skip to main content
Announcements
NEW: Seamless Public Data Sharing with Qlik's New Anonymous Access Capability: TELL ME MORE!
cancel
Showing results for 
Search instead for 
Did you mean: 
bdunsmoor
Contributor III
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
Labels (3)
1 Solution

Accepted Solutions
petter
Partner - Champion III
Partner - Champion III

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

View solution in original post

3 Replies
petter
Partner - Champion III
Partner - Champion III

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

Annotation 2019-07-18 083745.jpg

petter
Partner - Champion III
Partner - Champion III

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
Contributor III
Contributor III
Author

Thank you Peter.  That's worked perfectly.