note 38069 modified in function.checkdate by aidan
| From: | aidan@php.net | Date: | Thu, 10 Feb 2005 05:31:37 +0000 |
| Subject: | note 38069 modified in function.checkdate by aidan | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-84760@lists.php.net to get a copy of this message | ||
A method to calculate the days between two dates:
<?php
function diff_days($start_date, $end_date
{
return floor(abs(strtotime($start_date) - strtotime($end_date))/86400);
}
// You can use whatever days you want
echo diff_days("20031013", "20040105"); // result: 84
// You can use every format strtotime supports
echo diff_days("now", "-1 year");
// You can mix start and end
echo diff_days("20031203", "20031201"); // result: 2
?>
--was--
@carsten:
Your method to calculate the days between two dates doesn't need to be that complicated.
Try this (quick 'n' dirty):
<?php
function diff_days($start_date, $end_date
{
return floor(abs(strtotime($start_date) - strtotime($end_date))/86400);
}
// You can use whatever days you want
echo diff_days("20031013", "20040105"); // result: 84
// You can use every format strtotime supports
echo diff_days("now", "-1 year");
// You can mix start and end
echo diff_days("20031203", "20031201"); // result: 2
?>
http://php.net/manual/en/function.checkdate.php