1//get Date diff as intervals
2$d1 = new DateTime("2018-01-10 00:00:00");
3$d2 = new DateTime("2019-05-18 01:23:45");
4$interval = $d1->diff($d2);
5$diffInSeconds = $interval->s; //45
6$diffInMinutes = $interval->i; //23
7$diffInHours = $interval->h; //8
8$diffInDays = $interval->d; //21
9$diffInMonths = $interval->m; //4
10$diffInYears = $interval->y; //1
11
12//or get Date difference as total difference
13$d1 = strtotime("2018-01-10 00:00:00");
14$d2 = strtotime("2019-05-18 01:23:45");
15$totalSecondsDiff = abs($d1-$d2); //42600225
16$totalMinutesDiff = $totalSecondsDiff/60; //710003.75
17$totalHoursDiff = $totalSecondsDiff/60/60;//11833.39
18$totalDaysDiff = $totalSecondsDiff/60/60/24; //493.05
19$totalMonthsDiff = $totalSecondsDiff/60/60/24/30; //16.43
20$totalYearsDiff = $totalSecondsDiff/60/60/24/365; //1.35
1 date_default_timezone_set("Africa/Johannesburg");
2 $now = new DateTime();
3 $future_date = new DateTime('2020-10-21 00:00:00');
4
5 $interval = $future_date->diff($now);
6
7 echo ($interval->format("%a") * 24) + $interval->format("%h"). " hours". $interval->format(" %i minutes ");
8 print_r($now->format('Y-m-d H:i:s'));
9
1$timeFirst = strtotime('2011-05-12 18:20:20');
2$timeSecond = strtotime('2011-05-13 18:20:20');
3$differenceInSeconds = $timeSecond - $timeFirst;
4