How can I compare ISO dates in Javascript. Hour and Minute does not give correct results.
function ConvertDateNowToISODate() {
var currentDate = new Date().toISOString();
currentDate = new Date(currentDate).getTime();
return currentDate;
}
function ConvertToExpirationDateToISODate(expirationDate) {
var newDate = new Date(expirationDate).toISOString();
newDate = new Date(newDate).getTime();
return newDate;
}
function isFromBiggerThanTo(dtmfrom) {
var from= ConvertToExpirationDateToISODate(dtmfrom);
var to = ConvertDateNowToISODate();
if (from > to)
return "blue";
else if (to < from)
return "red";
else
return "grey";
}
dtmInputs= input1=2022-08-09T12:42:02.953, input2= 2022-10-08T05:00:00, input3= 2022-08-11T13:42:47.993, input4= 2022-10-08T14:35:00
my codes never drop in the red part like this. my codes never drop in the red part like this
CodePudding user response:
from > to
and to < from
are both the same. Silly mistake!
Change the second condition as to > from
.