RE: What's with 2016-11-06

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Thank you Richard for the explanation:

> DST. On both 2015-11-01 and 2016-11-06 the US switched back to standard time.

...and thank you Shiplu for the DateTime suggestion.  I used your suggestion to correct my program, but wanted to report a minor change needed in shiplu's example:

$d1->add(new DateInterval('PD1')); // generated error 'Unknown or bad format (PD1)'

$d1->add(new DateInterval('P1D')); // works

--
Clifford R. Nieuwenhuis
IT Manager
Architectural Design Consultants, Inc.
c.nieuwenhuis@xxxxxxxxxxxxxx
608-254-6181



 
From: muquaddim@xxxxxxxxx [mailto:muquaddim@xxxxxxxxx] On Behalf Of shiplu
Sent: Tuesday, October 25, 2016 9:18 AM
To: Cliff Nieuwenhuis
Cc: php-general@xxxxxxxxxxxxx
Subject: Re:  What's with 2016-11-06

If you want to traverse days between 2 dates, just use DateTime and DateInterval classess.

$d1 = new DateTime('2016-10-30');

$d1->add(new DateInterval('PD1'));

$d1 should point to next day now.
      

On Tue, Oct 25, 2016 at 4:10 PM, Cliff Nieuwenhuis <c.nieuwenhuis@xxxxxxxxxxxxxx> wrote:
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.

--
Clifford R. Nieuwenhuis
IT Manager
Architectural Design Consultants, Inc.
c.nieuwenhuis@xxxxxxxxxxxxxx
608-254-6181


--

Clifford R. Nieuwenhuis
IT Manager
Architectural Design Consultants, Inc.
c.nieuwenhuis@xxxxxxxxxxxxxx
608-254-6181

Visit our redesigned website:
www.adcidesign.com

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




-- 
Shiplu.Mokadd.im
Unix Hacker

Innovation distinguishes between follower and leader 
—  Steve Jobs

An expert is a person who has made all the mistakes that can be made in a very narrow field.
— Neils Bohr 




[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux