Answers for "php calculate diff between timestamps in seconds"

PHP
0

difference between two timestamps php

$datetime1 = new DateTime('2016-11-30 03:55:06');//start time
$datetime2 = new DateTime('2016-11-30 11:55:06');//end time
$interval = $datetime1->diff($datetime2);
echo $interval->format('%Y years %m months %d days %H hours %i minutes %s seconds');//00 years 0 months 0 days 08 hours 0 minutes 0 seconds
Posted by: Guest on September-04-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 "php calculate diff between timestamps in seconds"

Browse Popular Code Answers by Language