Source Code:
(back to article)
<?php $date1 = new DateTime('2022-01-01'); $date2 = new DateTime('2023-01-01'); $interval = $date1->diff($date2); if ($interval->invert == 1) { // $date2 is earlier than $date1 echo '$date2 is earlier than $date1'; } else { // $date1 is earlier than $date2 echo '$date1 is earlier than $date2'; }
Result:
Report an issue