VBScript → Lua
Please note: there is also a version for Lua based Call Routing available: #17: Be more flexible on dates! (Part 2 - Lua)
Within the GSE of you have a Time block which can be used to check (beside others) for time spans:
You might noticed already that in here it is not possible to take the dates (or times) from within variables. So only hard coded time spans can be checked with this block.
In case you need it more flexible and use variables this block can't be used. But the GSE wouldn't be the GSE if there wouldn't be another easy solution for this problem.
We just have to do the comparison by ourselves with a little bit of VBScript. Within VBScript there is a DateDiff function available, which returns the difference of two dates in any needed unit, like days, weeks, months, years.
Dim nDifference nDifference = DateDiff( "d", CDate("01.09.2019"), CDate("30.09.2019") )
This example calculates the difference between the 01.09.2019 and 30.09.2019 in days and stores it into a variable.
If the second date is larger/later than the first date, the result is a positive number. If the second date is smaller/earlier than the first date, the result is a negative number. The function CDate converts a given date into a VBScript "date" data type.
So to check if the current date is within a given time span, we need to call DateDiff two times. The first time to check if the current date is larger/later than the start date. The second time to check if the current date is smaller/earlier than the end date.
To do this, we simply use two Evaluate blocks in a row. To check if the current date is within a given time span, where the start date and end date is given in variables, we can simply use two such blocks:
Please note: in this example the start and end date are included in the time span. If you want them to be excluded from the time span just check for "> 0" and "< 0" instead of ">= 0" and "<= 0".
The current date is taken from the GSE build in function CurDate(). It would also be possible to use the VBSript function Now. The difference between both functions is, that CurDate() returns the date according the configured location time zone of the script user, while Now simply returns the date of the server machine.
To put everything together into a handy little script I have configured the two variables for start and end date as parameters of the GSE script, so they can be easily set from the call routing manager. If I am on vacation my voicemail will be started, otherwise I want my regular call routing to be executed.
And this is how it looks in the call routing manager:
So with a little bit of VBscript and two Evaluate blocks we are able to check for time spans ourselves and don't need the static/hard coded Time block.
You can download this tiny script from here:
PS: don't miss to take a look into the ECR Useful Link Collection