adding math

Technical support and scripting issues

Moderators: Dorian (MJT support), JRL

Post Reply
macroman
Pro Scripter
Posts: 91
Joined: Mon Jun 02, 2014 5:32 am

adding math

Post by macroman » Thu Oct 06, 2016 2:33 pm

How do I go about adding time/clock duration together? here's what I have and it's not populating:

Code: Select all

Let>test=0:17:53+0:17:53
mdl>%test%

User avatar
Marcus Tettmar
Site Admin
Posts: 7395
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Re: adding math

Post by Marcus Tettmar » Fri Oct 07, 2016 8:21 am

Hi,

You can't just add values like that - they are strings. We need to do a bit more work. We could do this:

Code: Select all

Let>time1=0:17:53
Let>time2=1:17:53

TimeDiff>00:00:00,time1,S,secondsTime1
TimeDiff>00:00:00,time2,S,secondsTime2
TimeAdd>00:00:00,S,{%secondsTime1%+%secondsTime2%},newTime

MessageModal>newTime
What we are doing here is finding the number of seconds from midnight for each time, adding them together and then adding that to midnight to return a new time.

Or we could use VBScript. Here's one way to do it in VBScript:

Code: Select all

VBSTART
  Function AddTimes(stime1,stime2)
    AddTimes = FormatDateTime(TimeValue(stime1)+TimeValue(stime2),3)
  End Function
VBEND

VBEval>AddTimes("0:17:53","1:17:53"),newTime
MessageModal>newTime
Both assume that hh:mm:ss is system standard time format. It would be further complicated if that wasn't the case.
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

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