JScript to compare 2 dates in Workflow

Trying to compare two dates in a workflow in a jscript - dates are not in same format.

Can’t get the jscript to work, I have googled “java compare dates”, but none of the soultions I can find works in a jscript in a workflow.
What am I missing here in the script, I have also tried formatter.date ?

var DateFormat = ‘yyyy-MM-dd hh:mm:ss’
var startInput = “2022-08-27 23:59:16”;
var stopInput = “2022/09/05 10:08:49”;

var DateStart = LocalDateTime.parse(startInput, DateFormat);
var DateStop = LocalDateTime.parse( stopInput, DateFormat);

if (DateStart < DateStop){
//do something
}
else {
//do something else
}

Hi @klaus.soerensen, I would expect that you will have to make use of the following JavaScript code for this:

var startInput = "2022-08-27 23:59:16";
var stopInput = "2022/09/05 10:08:49";

var dateStart = new Date(startInput);
var dateStop = new Date(stopInput);

if (dateStart.getTime() < dateStop.getTime()) {
    // Do something...
} else {
    // Do something else...
}

IMPORTANT! Please note that this doesn’t result in the expected result when executing the above JavaScript code by the Run Script Workflow plugin (tested in PReS Workflow version 2022.1.5). However, it seems that using the following line of JavaScript code instead does result in the expected result (different format):

//var startInput = "2022-08-27 23:59:16";
var startInput = "2022/08/27 23:59:16";

So an option might be to convert the first date to a different format by replacing the - characters by / characters.


Can’t get the jscript to work, I have googled “java compare dates”, but none of the soultions I can find works in a jscript in a workflow.

Please make sure that you’re searching for “javascript compare dates” instead of “java compare dates” because Java is a different programming language.

Thanks
Just added this line to replace - with /
startInput = startInput.replace(/-/g, ‘/’);