note 60555 deleted from function.date by derick

From: Date: Sun, 15 Jan 2006 12:33:54 +0000
Subject: note 60555 deleted from function.date by derick
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-101800@lists.php.net to get a copy of this message
Note Submitter: webmaster at techphreak dot com ---- 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; } ?>

« previous php.notes (#101800) next »