note 74132 deleted from function.date by bobby

From: Date: Tue, 27 Mar 2007 03:21:49 +0000
Subject: note 74132 deleted from function.date by bobby
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-124831@lists.php.net to get a copy of this message
Note Submitter: missilesilo at gmail dot com ---- I was tired of running into problems with Daylight Saving Time for calculating the date difference between two dates using timestamps. After all, I don't even care about the times. I only care about the dates. Here is a function using a simple algorithm to calculate the number of days since around the year 1 A.D. for the Gregorian calendar. This function can then be used to calculate the date difference between two dates. <?php function dayCount($y, $m, $d) { $m = ($m+9)%12; $y = $y-(int)($m/10); return 365*$y+(int)($y/4)-(int)($y/100)+ (int)($y/400)+(int)(($m*306+5)/10)+$d-1; } $dateDiff = dayCount(2007, 3, 18) - dayCount(2007, 3, 10); // Add 1 for an inclusive difference $dateDiff += 1; // Output is 9 ?>

« previous php.notes (#124831) next »