Warning: Solution 2 can result in a wrong date. The code:
new Date(...)
still uses your local machine timezone.
For instance, if you run this code in California you'd get:
2018-10-19 00:00:00 GMT-8
->
2018-10-19 10:00:00
in Germany (same day).
But if you run this code in Beijing, China, you'd get:
2018-10-19 00:00:00 GMT+8
->
2018-10-18 18:00:00
in Germany. The previous day!
If you want to get rid of timezone issues, I'd recommend you to always use UTC. For instance:
function toDate(datestr) {
var parts = datestr.split(".");
return new Date(Date.UTC(parts[2], parts[1] -1, parts[0]));
}
var comparestart = toDate("$Start");
var compareende = toDate("$Ende");
if (comparestart >= compareende) {
return true;
} else {
return false;
}
To display the date you can use any of the following:
date.toUTCString()
date.toLocaleString('de-DE', {timeZone: 'UTC'})
date.getUTCDate() + '.' + (date.getUTCMonth() + 1) + '.' + date.getUTCFullYear()