Days between two given dates using PHP?

January 10, 2010 | Filed Under PHP | Comments Off

$date1 = date(‘Y-m-d’); // yyyy-mm-dd  format
$date2 = ’2006-07-01′;
$days = (strtotime() – strtotime()) / (60 * 60 * 24);
echo “Number of days since ’2006-07-01′: $days”;

Where strtotime

int strtotime ( string $time [, int $now] )

The function expects to be given  a string containing a US English date format and will try to parse that format into a UNIX timestamp (the number of seconds since January 1 1970 00:00:00 GMT), relative to the timestamp given in now, or the current time if now is not supplied.

Comments

Comments are closed.

© PHPInterviewQuestion.com 2009 - 2012

eXTReMe Tracker