Learn How to find days between two dates in PHP

If you started writing a PHP script where the logic is in days, you many need to find days between two dates. This situation occurs often if you are working as a Professional PHP Web Developer.

Lets pick two dates and convert the string to time using strtotime(), then find the days dividing them by 60*60*24:

<?php

$date1 = '2013-11-10';
$date2 = '2013-11-01';

$diff = strtotime($date1) - strtotime($date2);
$days = $diff/(60*60*24). " days";

echo $days;

?>

I hope this would have helped you.

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top