I am beginner using bootstrap PDO and php. javascript How can I compare 2 date like image below.
Asked
Active
Viewed 38 times
0
-
1You're going to have to narrow down where you want to compare it. Bootstrap is mostly for CSS, so ignore that. If you want to alert the user immediately, then you'll need javascript. If you want to compare it after the form is submitted, then you'll need PHP. There are already a lot of answers on SO on how to compare dates in both languages. – aynber Feb 23 '22 at 15:01
-
2It would also be nice to know how you want to compare the dates. If you don't understand what I mean you could, instead, say **why** you want to compare them. – KIKO Software Feb 23 '22 at 15:14
1 Answers
0
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.

Jonas Oldenkott
- 30
- 7
-
-
Otherwise I made this code for modal when I tryu to ADD New record and it work fine. – user18290205 Feb 23 '22 at 15:58
-
Sorry for late response, but yes, it should work there aswell. – Jonas Oldenkott Feb 25 '22 at 10:38