note 44998 added to function.checkdate
| From: | steven at pluginz dot com | Date: | Sun, 22 Aug 2004 23:43:51 +0000 |
| Subject: | note 44998 added to function.checkdate | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-75136@lists.php.net to get a copy of this message | ||
There's a much easier way to count days, like the post above yours... because, remember: dates
are just numbers. ;-)
<?php
// the following can all be done in one line... heh
$start = "20030101";
$end = "20031231";
$et = strtotime($end); // 1072846800
$st = strtotime($start); // 1041397200
$diff = $et - $st;
$count = $diff / (60*60*24); // get days
$count++; // only if you want an inclusive count.
echo $count;
?>
Result: 365 (with the count incremented for inclusion)
The inclusive increment is necessary because subtraction just works that way, and to prove the
calculation above:
if $start = "20000101"
and $end = "20010101"
result is 366 days ... a leap year. :-)
QED
==_-+- Steve
----
Manual Page -- http://www.php.net/manual/en/function.checkdate.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+44998
Delete -- http://master.php.net/manage/user-notes.php?action=delete+44998&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+44998&report=yes
Search -- http://master.php.net/manage/user-notes.php