Convert multiple time period in string to days

Hi,

Can I please get help to convert the below different time periods to days.

Last Login
1 min 32 sec
1 hour 26 min
1 week 1 day
1 year 13 weeks
10 weeks 1 day
2 days 23 hours
3 hours 28 min

Thanks
Jag

Hi @JAGBI -

Here’s a sample workflow that may be of some use. It’s not a perfect solution by any means, but maybe you can take it from here.

DurationExtractionExample.knwf (22.0 KB)

Some things to note about this workflow:

  1. I had to tweak the text in the inputs to allow the String to Duration nodes to work (e.g., converting “min” to “minutes”). On a larger scale this would just require a String Manipulation node.
  2. The String to Duration node can’t handle processing dates and times all at once - it has to be one or the other. That’s why the workflow branches.
  3. Related to this: time periods that cross the date/time boundary (for example, 2 days {date} 23 hours {time}) aren’t handled correctly at all. This is the major deficiency of the workflow.
  4. I arbitrarily chose 365 days/year and 30 days/month in the Math Formula node, which obviously doesn’t always apply. It’s probably close enough though.

Results are below. Note that I’ve highlighted the result that is clearly incorrect.

2018-11-20%2013_29_46-Filtered%20table%20-%202_33%20-%20Column%20Filter%20(Clean%20up)

At any rate, I hope this helps get you started. Thanks for posting the question - I learned something new about these nodes as I worked through it :slight_smile:

(A completely different approach might be to just leave out the Duration nodes entirely, and instead parse the values of each row into date and time fields manually, followed by a math calculation.)

2 Likes