1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
<?php // PHP program to compare dates // Declare two dates and // initialize it $date1 = "1998-11-24"; $date2 = "1997-03-26"; // Use comparison operator to // compare dates if ($date1 > $date2) echo "$date1 is latest than $date2"; else echo "$date1 is older than $date2"; ?> |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
<?php // PHP program to compare dates // Declare two dates in different // format $date1 = "12-03-26"; $date2 = "2011-10-24"; // Use strtotime() function to convert // date into dateTimestamp $dateTimestamp1 = strtotime($date1); $dateTimestamp2 = strtotime($date2); // Compare the timestamp date if ($dateTimestamp1 > $dateTimestamp2) echo "$date1 is latest than $date2"; else echo "$date1 is older than $date2"; ?> |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
<?php // PHP program to compare dates // Declare two dates in different // format and use DateTime() function // to convert date into DateTime $date1 = new DateTime("12-11-24"); $date2 = new DateTime("2011-03-26"); // Compare the dates if ($date1 > $date2) echo $date1->format("Y-m-d") . " is latest than " . $date2->format("Y-m-d"); else echo $date1->format("Y-m-d") . " is older than " . $date2->format("Y-m-d"); ?> |
ที่มา : https://www.geeksforgeeks.org/comparing-two-dates-in-php/