[TriLUG] OT?: php anomaly

Donald J. Sipe III donald.sipe at gmail.com
Thu Aug 17 09:11:11 EDT 2006


Stan,

I think the problem is that the adding 86400 (the number of seconds in a
day) doesn't always land on 00:00:00 (ie exactly at midnight).  It may be
that it lands on 11:59:59, which will throw off the results--making the 29th
appear twice.  I've actually ran into this problem before, I guess I just
misunderstood the nature of your question at first.

To get around it, I've taken to using strtotime("+1 day", $now) to increment
time.  The function is more costly than some mathematical wizardry, but it
works and you don't need an abacus to follow the code.  That said, the new
code might look like this:

<?
$CurrentDate = strtotime("2006-10-24");
$EndDate     = strtotime("2006-11-15");
while ( $CurrentDate <= $EndDate ) {
       $ShortDate  = date("m-d"  , $CurrentDate);
       $MySQL4date = date("Y-m-d", $CurrentDate);
       echo $ShortDate . '(' . $CurrentDate . ')[' . $MySQL4date . "]\n";
       // $CurrentDate += 86400 ;
       $CurrentDate = strtotime("+1 day", $CurrentDate);
}
?>


Cheers,
DJ



More information about the TriLUG mailing list