1$today = date("Y-m-d");
2$expire = $row->expireDate; //from database
3
4$today_time = strtotime($today);
5$expire_time = strtotime($expire);
6
7if ($expire_time < $today_time) { /* do Something */ }
1<?php
2
3$datetime1 = new DateTime('2009-10-11 12:12:00');
4$datetime2 = new DateTime('2009-10-13 10:12:00');
5
6if ($datetime1 > $datetime2) {
7 echo 'datetime1 greater than datetime2';
8}
9
10if ($datetime1 < $datetime2) {
11 echo 'datetime1 lesser than datetime2';
12}
13
14if ($datetime1 == $datetime2) {
15 echo 'datetime2 is equal than datetime1';
16}
1$date1 = new DateTime("now");
2$date2 = new DateTime("tomorrow");
3
4var_dump($date1 == $date2); // false
5var_dump($date1 < $date2); // true
6var_dump($date1 > $date2); // false
7
1$date_now = date("Y-m-d h:i:s");
2$variable = new DateTime($date_now);
3$to_compare = "2018-06-01 12:48:09";
4$variable1 = new DateTime($to_compare);
5$difference = date_diff($variable, $variable1)->format("Difference => %Y years, %m months, %d days, %h hours, and %i minutes");
6echo $difference;
1$date1 = "2021-01-15";
2$date2 = "2021-01-18";
3
4if ($date1 < $date2) {
5 echo "$date1 is earlier than $date2";
6} else {
7 echo "$date1 is later than $date2";
8}