Converting hh:mm:ss to seconds.

Technical support and scripting issues

Moderators: Dorian (MJT support), JRL

Post Reply
Tourless
Pro Scripter
Posts: 69
Joined: Wed Jun 14, 2017 1:53 am
Location: NY

Converting hh:mm:ss to seconds.

Post by Tourless » Fri Apr 14, 2023 5:04 pm

Hi Folks.

I have a var that holds a time value as a string formatted as hh:mm:ss. I need to be able to parse that value into separate vars so I can perform the math to break it all down to total seconds. Once I have my total seconds I'll be able to do the rest of my math and convert any results back into hh:mm:ss, but my problem is not knowing how to parse out the values from my string. I'm pretty sure someone is going to say RegEx, which I'm looking at but I'm very confused by this command and this thing called easypatterns isn't helping make anything clearer for me.

If someone can get me started I'd be most grateful.

User avatar
Dorian (MJT support)
Automation Wizard
Posts: 1348
Joined: Sun Nov 03, 2002 3:19 am
Contact:

Re: Converting hh:mm:ss to seconds.

Post by Dorian (MJT support) » Fri Apr 14, 2023 5:24 pm

That would be hours x 3600 + mins x 60 + secs :

Code: Select all

//4hrs 15mins 30secs
Let>time=4:15:30
separate>time,:,elements

//=15330 secs
let>totalseconds={(%elements_1%*3600)+(%elements_2%*60)+(%elements_3%)}
Yes, we have a Custom Scripting Service. Message me or go here

Post Reply
Sign up to our newsletter for free automation tips, tricks & discounts