Jump to content

Get number of days remaining until a date


guttyguppy

Recommended Posts

  • 3 years later...

<?php

 

//Convert to date

$datestr="2013-02-06 19:10:18";//Your date

$date=strtotime($datestr);//Converted to a PHP date (a second count)

 

//Calculate difference

 

$diff=$date-time();//time returns current time in seconds

 

$days=floor($diff/(60*60*24));//seconds/minute*minutes/hour*hours/day);

 

$hours=round(($diff-$days*60*60*24)/(60*60));

 

 

//Report

echo "$days days $hours hours remain<br />";echo "<br>";

?>

Don't resurrect old threads.

 

But at least provide an up-to-date solution if you must.

 

$futureDate = '2013-12-25';
$d = new DateTime($futureDate);
echo $d->diff(new DateTime())->format('%a');  //--> 321

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.