Number of Days between Two Dates

Q

How can we know the number of days between two given dates in PHP?

✍: FYIcenter

A

Simple arithmetic:

<?php
$date1 = date('Y-m-d');
$date2 = '2006-07-01';
$days = (strtotime($date1) - strtotime($date2)) / (60
* 60 * 24);
$days = (int) $days;
echo "Number of days since '2006-07-01': $days";
?>

2007-02-27, 6423👍, 0💬