Re: Calculating dates
| From: | Jim Lucas | Date: | Sat, 01 Mar 2008 06:08:13 +0000 |
| Subject: | Re: Calculating dates | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-270794@lists.php.net to get a copy of this message | ||
Ron Piggott wrote:
Is there an easy way to calculate the number of days between two dates? Example: 2008-02-27 - 2007-12-03 = 86 days The dates will be in the format above YYYY-MM-DD RonThis should do the trick <?php $date1 = '2008-02-27'; $date2 = '2007-12-03'; $udate1 = strtotime($date1); $udate2 = strtotime($date2); $factor = 86400; $difference = (($udate1 - $udate2) / $factor); echo "The difference is {$difference} days"; Jim