note 60555 added to function.date
| From: | webmaster at techphreak dot com | Date: | Wed, 11 Jan 2006 02:30:08 +0000 |
| Subject: | note 60555 added to function.date | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-101523@lists.php.net to get a copy of this message | ||
Here is a PHP function to calculate the number of days since a date in the past. It may not be 100%
effective but I think it works good! (I haven't given it but about 6 trys) It uses strtotime()
for date input.
Good Luck and Regards from Southern Miss, USA
<?php
print (day_calculator("Nov 28 2005") .
" days since PHP 5.1.1 was released to the public");
function day_calculator($then="") {
$then = strtotime($then);
$now = time();
$thisyear = date("Y", $now);
$thatyear = date("Y", $then);
$x = 0;
if ($thisyear != $thatyear) {
for($s=$thatyear;$s<=$thisyear;$s++) {
if (date("L", strtotime("Jan 1 $s"))) { $x += 1; }
if ($s == $thatyear) {
$x += (365 - date("z", $then));
} else if ($s == $thisyear) {
$x += date("z", $now);
} else {
$x += 365;
}
}
} else {
$x += (date("z", $now) - date("z", $then));
if (date("L", strtotime("Jan 1 $thisyear"))) { $x += 1; }
}
return $x;
}
?>
----
Manual Page -- http://www.php.net/manual/en/function.date.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+60555
Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+60555&report=yes&reason=added+to+the+manual
Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+60555&report=yes&reason=bad+code
Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+60555&report=yes&reason=spam
Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+60555&report=yes&reason=useless
Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+60555&report=yes&reason=non-english
Delete: already in docs -- http://master.php.net/manage/user-notes.php?action=delete+60555&report=yes&reason=already+in+docs
Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+60555&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+60555&report=yes
Search -- http://master.php.net/manage/user-notes.php