Need Help Doing time based calculations

Hi Everyone,

I hope the New Year is shaping up fine for everyone!

I need to add time to a specific time format. Here is what my application is giving me as time as a cursor playback position:

00:00:00.964 which equals hours : minutes : seconds : milliseconds

I would like to create a create a macro that copies whatever the current cursor position is (it will be in the above text format and add (say) 10 seconds to it. Of course there will be other actions taking place, but this is the one area I’m at a loss.

So… the macro would read: 00:00:00.964 and return: 00:00:10.964 after adding 10 seconds

Another example: the macro would read: 00:00:59.964 and return: 00:01:09.964 after adding 10 seconds.

Any ideas on how to accomplish this?

Thanks.

Cheers,

Andrew K

Use the Set Variable to Text %CurrentClipboard% action to copy the value into a variable.

Use the Search Variable action for (\d+):(\d+):(\d+.\d+) to break the time apart into Hours, Minutes, Seconds.

Use the Set Variable Time to Calculation Hours * 3600 + Minutes * 60 + Seconds to get a time in seconds.

Use the Set Variable Time to Calculation to do your arithmetic.

Use Set Variable Hours to Calculation TRUNC( Time/3600 ) - format as 00

Use Set Variable Minutes to Calculation TRUNC( (Time - 3600*Hours)60 ) - format as 00

Use Set Variable Seconds to Calculation Time - 3600Hours - 60Minutes - format as 00.000

Then Set Clipboard to Text %Variable%Hours%:%Variable%Minutes%:%Variable% Seconds%

Something like that should do the trick.

4 Likes

Perfect!!

I thought I might have to split up the variables and concatenate them in the end, but thought maybe there was a simpler way. I figured you would know if there was a simpler way.

Thanks for being so active on the forum Peter!!

Cheers,

Andrew K

Sometimes the client will be very lenient in what it accepts and so maybe it will accept things like:

00:75:84.357

(ie, seconds or minutes that exceed 60)

or even:

9567.567

(ie, just seconds).

If so, then you can simplify some of your calculations. For example, 00:05:55 + 10 seconds could be 00:05:65. Just add 10 seconds to the seconds field and leave the rest of the string as it is.

A good idea is to make two sub-macros that handle converting the string into a time in seconds, and a macro that converts the time from seconds into time format. Then you can reuse those using the Execute Macro action.

2 Likes

Yeah... I think you are right. Can't hurt!

Thanks again!

Cheers,

Andrew K