Number of days between two dates

<?php /** * Calculate the number of days between two dates. * The order of the dates is irrelevant. * @param string $date1 The first date * @param string $date2 The second date * @return int * @author Sunny Walker <www.miraclesalad.com> */ function daysDiff($date1, $date2) { return abs(strtotime($date1)-strtotime($date2))/86400; } ?>
Calculate the number of days between two dates. The order of the dates is irrelevant and any date format supported by http://php.net/strtotime should work.

3 Responses

Hi, Sorry I'm a PHP newbie. Where to put in the two dates and in which format?

Thank you ;)
You can put the dates in any format accepted by http://php.net/strtotime so daysDiff('2016-02-01', '21/11/2011') would work.
It doesn't matter which order you put in the dates.
and
will both return the same result (2).

Write a comment

You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.