Answers for "calculate time difference php"

PHP
-1

calculate time difference php

$time1 = new DateTime('09:00:59');
$time2 = new DateTime('09:01:00');
$interval = $time1->diff($time2);
echo $interval->format('%s second(s)');

Result: 1 second(s)
Posted by: Guest on December-24-2020
0

php time difference in hours

date_default_timezone_set("Africa/Johannesburg");
    $now = new DateTime();
    $future_date = new DateTime('2020-10-21 00:00:00');
    
    $interval = $future_date->diff($now);
    
    echo ($interval->format("%a") * 24) + $interval->format("%h"). " hours". $interval->format(" %i minutes ");
    print_r($now->format('Y-m-d H:i:s'));
Posted by: Guest on October-20-2020
0

php calculate time difference in percentage

First, make those minutes into seconds:

4 min 35 sec = 275 seconds

11 min = 660 seconds

Your 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:

$maxTime = 660;
$timeTaken = 275;

$percentage = ($timeTaken / $maxTime) * 100;

// To get percentage of time left
$percentLeft = (($maxTime - $timeTaken) / $maxTime) * 100;
Posted by: Guest on June-25-2021

Code answers related to "calculate time difference php"

Browse Popular Code Answers by Language