I am trying to use datetime variables but the limitations of Automise are becoming frustrating.
Two variables, both datetime
If compared using If…, they are converted to string before comparison. The online help says “Use %VariableName% syntax to compare the values of variables. String, integer or floating point values can all be compared.”
To work around this, I can set the format string to “yyyy-mm-dd hh:nn:ss” (noting that the default format is “c”, which is locale-dependent so could be different for different installations).
Now the If… works
Subsequently, in a “Fileset define” action I have a filter that restricts files to ones that have been created after a date specified by the variable.
This fails with the following error:
“Error converting string to date/time: ‘2019-08-23 16:16:40’ is not a valid date and time”
So the formatting has broken this comparison. It is as if all datetime variables are converted to string before comparison but the fileset doesn’t recognise the format.
Can datetime be supported natively for comparisons?
I’m not exactly sure why this wasn’t done before (possibly due to the pre-at5 variables architecture limitations), but I have added support for datetime comparisons without conversion to string to the If…Then action and the Fileset datetime filter.
Note these only work when the value is a simple variable reference (with no other text) and the variable types are both set to DateTime.
Thanks, that’s a very quick response! I’d feel more comfortable applying the update if all actions that can do comparisons on datetime variables were converted, as it will be difficult to remember what supports the improvement and what doesn’t.
Just discovered this thread as I was looking to add a day to a given date variable, and found I could not do it. Does this enhancement allow for that as well as the straight comparison of dates?