Good time.
How can i Get different time to end of the current day?
For example i would like get this output when i run my PHP script:
19 hours 35 minutes 13 seconds to end of current day
Thanks
Good time.
How can i Get different time to end of the current day?
For example i would like get this output when i run my PHP script:
19 hours 35 minutes 13 seconds to end of current day
Thanks
Use this concept:
/**
* Calculate the remaining time of the day in procedural style
*/
//get current time
$now = time();
//get tomorrow's time
$tomorrow = mktime(0, 0, 0, date('m'), date('d') + 1, date('Y'));
//get the remaining time in second
$rem = $tomorrow - $now;
$rem is the remaining time in seconds. You just need to divide it by 60 to get how many minutes. Divide it again by 60 to get how many hours.
Reference Howto: Calculate remaining time
Hope this will help you out..
echo remainingTime();
function remainingTime()
{
$string="";
$date= date("Y-m-d H:i:s");
$endDate= date("Y-m-d")." 23:59:59";
$remainingSeconds=strtotime($endDate)-strtotime($date);
$string.=gmdate("H", $remainingSeconds)." hours ";
$string.=gmdate("i", $remainingSeconds)." minutes ";
$string.=gmdate("s", $remainingSeconds)." seconds to the end of current day";
return $string;
}
<?php
$datetime1 = new DateTime();
$datetime2 = new DateTime('tomorrow');
$datetime2->format('Y-m-d H:i:s');
$interval = $datetime1->diff($datetime2);
echo $interval->format('%h hours %i minutes %s seconds');
?>
Possible output is 8 hours 38 minutes 46 seconds