tags:

views:

1145

answers:

3

Given a certain date, whats the easiest way to determine how many days until that date (in PHP)? I am trying to build a count-down widget, Thanks!

+4  A: 

From here:

<?php 
$cdate = mktime(0, 0, 0, 12, 31, 2009, 0);
$today = time();
$difference = $cdate - $today;
if ($difference < 0) { $difference = 0; }
echo "There are ". floor($difference/60/60/24)." days remaining";
?>
schnaader
+2  A: 

Don't treat dates as integers. Use your database, which has good support for dealing with calendars/time.

select datediff("2009-11-12", now())
troelskn
unix timestamp FTW
andufo
A: 

PHP 5.3 has introduced the DateTime class that implements a 'diff' function. See http://www.php.net/manual/en/datetime.diff.php

schuilr