Date Arithmetic COM
ActiveBatch Date Arithmetic also supports a programmatic COM interface. This allows COM accessible languages the ability to issue Date Arithmetic operations as part of their language. The library AbatComDateSub provides this ability. A single object named DateSub is provided. This object provides three (3) methods: GetDate, GetDateString and Reset.
GetDate – Compute Date Arithmetic Expression and return OLE date.
This method has the following usage syntax requirements:
GetDate (DateExp, [Date], [SimulatedDate]) as OutputDate
Where:
Input
DateExp (string) is a parameter representing a valid Date Arithmetic expression (i.e. <BOM>).
Date (date), if specified, is used to satisfy the <DATE> tag. If omitted, the <DATE> tag uses today’s value.
SimulatedDate (date) is an optional parameter that if specified can be used in place of today’s date. This means that the tag <TODAY> as well as any other tag will use this value for computation purposes. SimulatedDate is therefore useful when you want to see what other dates will generate for the specified tag(s).
Output
OutputDate (date) is the resultant computed date.
GetDateString – Compute Date Arithmetic Expression and return date as a string.
This method has the following usage syntax requirements:
GetDateString (DateExp, [Date], [SimulatedDate]) as OutputDateString
Where:
Input
DateExp (string) is a parameter representing a valid Date Arithmetic expression (i.e. <BOM>).
Date (date), if specified, is used to satisfy the <DATE> tag. If omitted, the <DATE> tag uses today’s value.
SimulatedDate (date) is an optional parameter that if specified can be used in place of today’s date. This means that the tag <TODAY> as well as any other tag will use this value for computation purposes. SimulatedDate is therefore useful when you want to see what other dates will generate for the specified tag(s).
Output
OutputDateString (string) is the resultant computed date.
Note: The only difference between the two (2) methods above is that the output date is either passed back as an OLE Date or a String.
Reset – Clear Memory Calendar Cache
This method requires no arguments and is used to clear any cached calendar files that you may have specified through previous date expression tags. By default, Date Arithmetic caches any calendar files specified for improved performance. If you modify a calendar you should invoke this method to reset the cache.
Date Arithmetic COM Example
This sample vbscript is using the ActiveBatch Date Arithmetic COM facility. Dates are passed back in Date and String format. Remember that in the Date format the display obeys regional settings.
Option Explicit
dim i,datesub, inputtag(18), outputdate, outputdatestr
Set datesub =createobject("AbatComDateSub.DateSub")
inputtag(1) = "<TODAY> "
inputtag(2) = "<TOMORROW> "
inputtag(3) = "<YESTERDAY>"
inputtag(4) = "<BOM> "
inputtag(5) = "<EOM> "
inputtag(6) = "<BOW> "
inputtag(7) = "<EOW> "
inputtag(8) = "<BOY> "
inputtag(9) = "<EOY> "
inputtag(10) = "<BOQ> "
inputtag(11) = "<EOQ> "
inputtag(12) = "<MONDAY> "
inputtag(13) = "<Tuesday> "
inputtag(14) = "<Wednesday>"
inputtag(15) = "<Thursday> "
inputtag(16) = "<Friday> "
inputtag(17) = "<Saturday> "
inputtag(18) = "<SUNDAY> "
for i = 1 to 18
outputdate = datesub.GetDate(inputtag(i))
outputdatestr = datesub.GetDateString(inputtag(i))
wscript.echo "the inputtag is : " & inputtag(i)
wscript.echo vbtab & " the outputdate is: " & outputdate & " ... the outputdateString is: " & outputdatestr
next
wscript.echo "Done"
Feel free to test the above script by creating a script-type Job in ActiveBatch. Copy and paste the script, set the script extension to .vbs, then run the Job on a Windows Execution Agent. After a successful execution, view the log file. You should see a log similar to what is depicted below (with different dates).
The output of this script, run on Friday, October 13, 2023, would look like this:
Microsoft (R) Windows Script Host Version 5.812
Copyright (C) Microsoft Corporation. All rights reserved.
the inputtag is : <TODAY>
the outputdate is: 10/13/2023 ... the outputdateString is: 13Oct23
the inputtag is : <TOMORROW>
the outputdate is: 10/14/2023 ... the outputdateString is: 14Oct23
the inputtag is : <YESTERDAY>
the outputdate is: 10/12/2023 ... the outputdateString is: 12Oct23
the inputtag is : <BOM>
the outputdate is: 10/1/2023 ... the outputdateString is: 01Oct23
the inputtag is : <EOM>
the outputdate is: 10/31/2023 ... the outputdateString is: 31Oct23
the inputtag is : <BOW>
the outputdate is: 10/9/2023 ... the outputdateString is: 09Oct23
the inputtag is : <EOW>
the outputdate is: 10/15/2023 ... the outputdateString is: 15Oct23
the inputtag is : <BOY>
the outputdate is: 1/1/2023 ... the outputdateString is: 01Jan23
the inputtag is : <EOY>
the outputdate is: 12/31/2023 ... the outputdateString is: 31Dec23
the inputtag is : <BOQ>
the outputdate is: 10/1/2023 ... the outputdateString is: 01Oct23
the inputtag is : <EOQ>
the outputdate is: 12/31/2023 ... the outputdateString is: 31Dec23
the inputtag is : <MONDAY>
the outputdate is: 10/9/2023 ... the outputdateString is: 09Oct23
the inputtag is : <Tuesday>
the outputdate is: 10/10/2023 ... the outputdateString is: 10Oct23
the inputtag is : <Wednesday>
the outputdate is: 10/11/2023 ... the outputdateString is: 11Oct23
the inputtag is : <Thursday>
the outputdate is: 10/12/2023 ... the outputdateString is: 12Oct23
the inputtag is : <Friday>
the outputdate is: 10/13/2023 ... the outputdateString is: 13Oct23
the inputtag is : <Saturday>
the outputdate is: 10/14/2023 ... the outputdateString is: 14Oct23
the inputtag is : <SUNDAY>
the outputdate is: 10/15/2023 ... the outputdateString is: 15Oct23
Done
The differences between the Date and String formats become obvious. The Date format obeys regional settings when displayed and the String format uses the ActiveBatch default. We could reformat the date using the /FORMAT qualifier as a modifier on the date tags. As you can also see the tags are case-insensitive.