I am beginner using bootstrap PDO and php. javascript How can I compare 2 date like image below.
CodePudding user response:
It depens on when/where u want to compare them. While filling out the form will require JS/Jquery. After submitting requires PHP.
In PHP it should work like this:
$date1 = "2022-02-02";
$date2 = "2021-01-01";
$dateTime1 = strtotime($date1);
$dateTime2 = strtotime($date2);
if ($dateTime1 > $dateTime2){
echo "$date1 is latest than $date2";
}else{
echo "$date1 is older than $date2";
}
PHP manual strtotime().
For JQuery use this thread.
CodePudding user response:
To compare dates you can use the .toString()
method:
const d1 = new Date('2019-06-01');
const d2 = new Date('2018-06-01');
const d3 = new Date('2019-06-01');
console.log(d1.toString() === d2.toString()); // false
console.log(d1.toString() === d3.toString()); // true