[prev in list] [next in list] [prev in thread] [next in thread] 

List:       php-general
Subject:    [PHP] RE: What's with 2016-11-06
From:       Domain nikha.org <mail () nikha ! org>
Date:       2016-10-25 20:56:26
Message-ID: B4A98F30964604514E9F3E7065794801-mail () nikha ! org
[Download RAW message or body]

Cliff Nieuwenhuis am Dienstag, 25. Oktober 2016 - 16:10:
> This is a stripped-down version of a calendar program.  Can anyone explain why \
> November 6 2016 appears twice? Or 2015-11-01? 
> I'm assuming the fault lies with
> 
> $calday = $calday + (60 * 60 * 24);
> 
> ...but I'd like to know why some days apparently have less than 86400 seconds and \
> how (efficiently) to work around that. 
> Here is my code:
> 
> $calday = strtotime('2016-10-30');
> $finish = strtotime('2016-12-01');
> 
> while ( $calday < $finish ) {
> for ($dow = 0; $dow < 7; $dow++) {
> 
> // set the year, month, and day
> $year = (int) date('Y', $calday);
> $month = (int) date('n', $calday);
> $day = (int) date('j', $calday);
> 
> echo "Year: $year, Month: $month, Day: $day, Day of Week: $dow <br />n";
> 
> // move on to the next day
> $calday = $calday + (60 * 60 * 24);
> }
> echo "* * *<br />n";
> }
> 
> Thanks in advance for any help.
> 

Dear Cliff!
You must care about the daylight savings. Indeed NOT every day has 86400 seconds. The \
simply addition fail for the switching days and this will brake all the rest in your \
calendar code.

Solution: calculate the timestamp for every single day with the appropriate function \
- as you are doing with strtotime().

Good luck,
Niklaus

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic