Don’t use adding 86400 seconds in real life

Consider the following example:

$date = strtotime('23 Oct 2009 00:00:00');
$end  = strtotime('26 Oct 2009 00:00:00');
while($date < $end )
{
    echo date('Y-m-d',$date).PHP_EOL;
    $date += 86400;
 
}
it will output:
2009-10-23
2009-10-24
2009-10-25
2009-10-25
rather than expected:
2009-10-23
2009-10-24
2009-10-25
2009-10-26
This is because of Daylight Saving Time, if you add hours :

it will output:
2009-10-232009-10-242009-10-252009-10-25
rather than expected:2009-10-232009-10-242009-10-252009-10-26
This is because of Daylight Saving Time, if you add hours :

echo date('Y-m-d',$date).PHP_EOL;

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.