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$period = new DatePeriod(
2 new DateTime('2010-10-01'),
3 new DateInterval('P1D'),
4 new DateTime('2010-10-05')
5);
6
7//Which should get you an array with DateTime objects.
8
9//To iterate
10
11foreach ($period as $key => $value) {
12 //$value->format('Y-m-d')
13}
1Select if(Date('2020-10-01') > Date('2020-11-01'), '1', '2' ) as rslt_date