1$time1 = new DateTime('09:00:59');
2$time2 = new DateTime('09:01:00');
3$interval = $time1->diff($time2);
4echo $interval->format('%s second(s)');
5
6Result: 1 second(s)
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
1First, make those minutes into seconds:
2
34 min 35 sec = 275 seconds
4
511 min = 660 seconds
6
7Your percentage of remaining time will be (275 / 660) * 100. The percentage of time left would be ((660 - 275) / 660) * 100. Of course, that's all in seconds. Don't know how you are receiving that time in php, but it might look like:
8
9$maxTime = 660;
10$timeTaken = 275;
11
12$percentage = ($timeTaken / $maxTime) * 100;
13
14// To get percentage of time left
15$percentLeft = (($maxTime - $timeTaken) / $maxTime) * 100;