user2571510 user2571510 - 6 months ago 46
PHP Question

PHP: calculate days between date and today

if I have a given date in the format yyyy-mm-dd, how can I calculate the difference in days to the current date ?

I just want to check whether this date is more than one week (7 days) old compared to the current date.

Many thanks in advance for any help with this, Tim.

$from = strtotime('2013-11-01');
$today = time();
$difference = $today - $from;
echo floor($difference / 86400);  // (60 * 60 * 24)


$datetime1 = new DateTime('2013-11-01');
$datetime2 = new DateTime('2013-11-15');
$interval = $datetime1->diff($datetime2);
echo $interval->format('%a');