note 38069 modified in function.checkdate by vrana
| From: | vrana@php.net | Date: | Tue, 17 Aug 2004 14:54:09 +0000 |
| Subject: | note 38069 modified in function.checkdate by vrana | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-79962@lists.php.net to get a copy of this message | ||
@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
?>
--was--
@carsten:
Your method to calculate the days between two dates doesn't need to be that complicated.
Try this (quick 'n' dirty):
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