There are a couple of issues here.
First, you can’t refer to process or global variables with ${Duedate}
. The proper syntax is either:
Watch.ExpandString("%{DueDate}")
orWatch.GetVariable("DueDate")
Second, process and global variables in Workflow are always of type String. So when using the new Date()
syntax, you have to make sure that the string format you pass as a parameter will be interpreted correctly by the Date()
object to automatically convert it to a date. But that conversion is highly dependent on your Windows Locale settings.
For instance, on my system::
// %{DueDate} contains "2025/06/01"
var dueDateTxt = Watch.ExpandString("%{DueDate}");
var dueDate = new Date(dueDateTxt);
var today = new Date();
Watch.log(datediff(today,dueDate),2); // Returns 32 when today is April 30
function datediff(first, second) {
return Math.round((second - first) / (1000 * 60 * 60 * 24));
}
But if the DueDate process variable contains 2025-06-01
, then the result is undefined (because that format is not understood by the Date
object).