Jump to content

#3: Be more flexible on dates!

Tom Wellige



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" instead of ">= 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.





Rule properties:







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





Recommended Comments

Hallo Herr Wellige 😀


ich bin gerade dabei ein Call Routing zu bauen, wo die Nutzer "einfach" Ihre Urlaubszeit eintragen können.

Das hier angebrachte Skript funktioniert leider nicht mehr, das Gespräch wird beendet.

Gibt es hier ggf. ein Update für die momentan aktuellste Version 13.25?


Danke schon einmal

M. Schulze


getestet mit VBS nicht LUN

Link to comment
On 2/14/2023 at 9:36 AM, Martin Schulze said:

Gibt es hier ggf. ein Update für die momentan aktuellste Version 13.25?


Nein, das Skript läuft auf JEDER SwyxWare Version. Das ist das schöne am Call Routing ;) 


Ich habe aber nochmal etwas genauer nachgesehen, und einen logischen Fehler gefunden. Der ist nun behoben und das Skript läuft einwandfrei auf meinem 13.25er Testsystem. Der Download oben im Blog Post ist aktualisiert.


Das war allerdings nur ein logischer Fehler, d.h. das Ende des Urlaubs wurde nicht richtig erkannt. Das hat aber zu keinen Skript/Ruf Abbruch geführt. Das klingt mir eher danach, dass da ein anderes Problem vorliegt, was nichts mit dem Skript aus dem Download zu tun hat.


Ein Blick in das Server Trace sollte hier schnell Klarheit bringen.



Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Create New...

Important Information

By using this site, you agree to our Terms of Use and have taken note of our Privacy Policy.
We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.