TIME CONVERSIONS- time to seconds
Application Type
Traditional Web

Good day. I have time stored in the database eg 30 mins is stored as 00:30:00 and I would like to convert this time to seconds. So i can use it on a function that requires an integer input. 

How do I convert time to seconds eg 01:00:00= 1hr =3600.


mvp_badge
MVP
Solution

Hello there Rudo,

Hope you're doing well.


You can achieve that using DiffSeconds() built-in function.

You can use this function and 2 Time variables. The first one should be a default for 00:00:00, like this:


The other should be your Time variable. Let's call it MyTime for this example.


So you can have an expression like this:

DiffSeconds(ZeroTime, MyTime)


Meaning you will calculate the difference between your time and "00:00:00" in seconds.

If I define MyTime variable like this:

Then the Result of the expression above is 9000 seconds, which is exactly the value that we are looking for:

2 (hours) x 60 (minutes) x 60 (seconds) + 30 (minutes) x 60 (seconds) = 7200 + 1800 = 9000 seconds


An alternative would be to convert that Time to a Text variable, then use the Substr() built-in function to get the hours and multiply by 3600 (to convert to seconds), then do the same to get the minutes and multiply by 60 and do the same for the seconds. In the end, sum all of these values.


Hope that this helps you!


Kind regards,

Rui Barradas

Thank you so much

Community GuidelinesBe kind and respectful, give credit to the original source of content, and search for duplicates before posting.