[TriLUG] OT?: php anomaly

stan briggs stan at StanBriggs.com
Thu Aug 17 09:17:02 EDT 2006


DJ,

that works.

thanks for your effort!

stan

p.s. i do wish, though, that i understood why, on a single day of each year,
adding 86400 (seconds) to the day only adds 23 hours. 

-----Original Message-----
From: trilug-bounces at trilug.org [mailto:trilug-bounces at trilug.org] On Behalf
Of Donald J. Sipe III
Sent: Thursday, August 17, 2006 9:11 AM
To: Triangle Linux Users Group discussion list
Subject: Re: [TriLUG] OT?: php anomaly

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
-- 
TriLUG mailing list        : http://www.trilug.org/mailman/listinfo/trilug
TriLUG Organizational FAQ  : http://trilug.org/faq/ TriLUG Member Services
FAQ : http://members.trilug.org/services_faq/




More information about the TriLUG mailing list