I am facing an problem in javascript. I want to do check if Date is expired or if Date is expired soon.
My Code:
//user date can be changed etc 2020-05-21, 2020-07-21
var selectedText = "2020-06-21"; //user enter a date
var selectedDate = new Date(selectedText).toLocaleDateString();
console.log("userdate",selectedDate);
var d = new Date(); //date 10 days ago
var days = d.setDate(d.getDate() - 10);
var soon = new Date(days).toLocaleDateString();
console.log('10 days ago was: ',soon );
var now = new Date().toLocaleDateString(); //current date
console.log("now",now);
if (selectedDate < now) { //date expired
console.log("Date must be in the future");
console.log("Date expired");
}
else if(selectedDate >= soon && selectedDate < now){ //date will expired soon
console.log("Date 10 days ago");
console.log("Date will be expire soon");
}Problem they just check IF condition they don't check ELSE conditon. I want to make condition if Date expired or if Date will be expire soon.
What should i do? Anyone help me?
Aucun commentaire:
Enregistrer un commentaire