Date Calulations

Technical support and scripting issues

Moderators: Dorian (MJT support), JRL

Post Reply
gchichester
Pro Scripter
Posts: 132
Joined: Mon Dec 22, 2008 4:56 pm
Location: St Augustine FL

Date Calulations

Post by gchichester » Tue Jun 28, 2011 1:37 pm

Needing a Simple Date Calculation

[code]
GetDate>Date
Let>aDate = {(%Date%) + (31)}
MDL>%aDate%
[/code]

I tried this and got 06/28/201131

I would like to add xx# of days to Date

Thanks for any and all suggestions

Gil

adroege
Automation Wizard
Posts: 438
Joined: Tue Dec 07, 2004 7:39 pm

Post by adroege » Tue Jun 28, 2011 1:48 pm

Try this...

Code: Select all

VBStart
VBEnd

VBEval>DateAdd("d",31,Date),result
MessageModal>result

gchichester
Pro Scripter
Posts: 132
Joined: Mon Dec 22, 2008 4:56 pm
Location: St Augustine FL

Date Calculations

Post by gchichester » Tue Jun 28, 2011 2:03 pm

adroege,
Thanks for the fast response
And I'm sorry but in my haste to post a message I failed to provide complete info about how I'm using this Date Calculation.
I'm not sure how to use the VBStart and VBEnd in this situation.
Maybe a function that I can call?

First it's a sub that's part of Dialog

[code]
SRT>subArvDate
GetDialogProperty>BolDialog,DischargePort,Text,DPort
If>Dport=JEDDAH
GetDate>ArvDate
Let>ArDate={(%ArvDate%) + (31)}
SetDialogProperty>BolDialog,ArrivalDate,Text,%ArDate%
EndIf
MDL>%ArDate%
END>subArvDate
[/code]

Gil

adroege
Automation Wizard
Posts: 438
Joined: Tue Dec 07, 2004 7:39 pm

Post by adroege » Tue Jun 28, 2011 2:11 pm

The VBStart and VBEnd can go anywhere. Just put them at the very top of your code and forget about them. Having them in the script is just a hint to Macro Scheduler that it will need to use the VBScript module at some point.

It is the VBEval> that does the work of adding the interval to the date.

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

Post by Marcus Tettmar » Tue Jun 28, 2011 2:11 pm

Code: Select all

//stick these two lines right at the top of your script once and forget about them.
VBSTART
VBEND

..
..
..
//modify your subroutine thusly:
SRT>subArvDate
GetDialogProperty>BolDialog,DischargePort,Text,DPort
  If>Dport=JEDDAH
  GetDate>ArvDate   
   VBEval>DateAdd("d",31,"%ArvDate%"),ArDate
SetDialogProperty>BolDialog,ArrivalDate,Text,%ArDate%
  EndIf
MDL>%ArDate% 
END>subArvDate
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

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

User avatar
JRL
Automation Wizard
Posts: 3503
Joined: Mon Jan 10, 2005 6:22 pm
Location: Iowa

Post by JRL » Tue Jun 28, 2011 2:12 pm

I nthis case you don't need vb. Just use the MS Add> function.

Code: Select all

SRT>subArvDate
GetDialogProperty>BolDialog,DischargePort,Text,DPort
  If>Dport=JEDDAH
  GetDate>ArDate
   Add>ArDate,31
SetDialogProperty>BolDialog,ArrivalDate,Text,%ArDate%
  EndIf
MDL>%ArDate% 
END>subArvDate

gchichester
Pro Scripter
Posts: 132
Joined: Mon Dec 22, 2008 4:56 pm
Location: St Augustine FL

Date Calculations

Post by gchichester » Tue Jun 28, 2011 2:23 pm

Thank you, Both
Just curious, is one faster then the other, when script is compiled?
Not that it's any real heavy lifting going on.
But inquiring minds just want know

User avatar
JRL
Automation Wizard
Posts: 3503
Joined: Mon Jan 10, 2005 6:22 pm
Location: Iowa

Post by JRL » Tue Jun 28, 2011 2:52 pm

Code: Select all

VBSTART
VBEND

VBEval>timer,stime
Let>vbcount=0
Repeat>vbcount
  Add>vbcount,1
  GetDate>ArvDate
  VBEval>DateAdd("d",31,"%ArvDate%"),ArDate
Until>vbcount=10000
VBEval>timer-%stime%,etime

mdl>VB time = %etime%

VBEval>timer,stime
Let>vbcount=0
Repeat>vbcount
  Add>vbcount,1
  GetDate>ArDate
  add>ardate,31
Until>vbcount=10000
VBEval>timer-%stime%,etime

mdl>MS time = %etime%

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