1

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

Amir m
  • 39
  • 1
  • 7
  • can you describe more what you want and what problem you are facing during implementing this? – Mubashar Iqbal Apr 27 '17 at 09:36
  • 1
    Possible duplicate of [How to calculate the difference between two dates using PHP?](http://stackoverflow.com/questions/676824/how-to-calculate-the-difference-between-two-dates-using-php) – Tom Apr 27 '17 at 09:40
  • duplicate [question](http://stackoverflow.com/questions/5906686/php-time-remaining-until-specific-time-from-current-time-of-page-load) Next time use google... faster than asking a duplicated question – VikingCode Apr 27 '17 at 09:40
  • @Amirm Hope my post will help you out.. – Sahil Gulati Apr 27 '17 at 09:53

3 Answers3

0

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

Nikko Madrelijos
  • 545
  • 3
  • 10
0

Hope this will help you out..

Try this code snippet here

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;
}
Sahil Gulati
  • 15,028
  • 4
  • 24
  • 42
0
<?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

Ahmed Ginani
  • 6,522
  • 2
  • 15
  • 33