arrays - PHP DateTime object, unexpected results -
i have 2 datetime objects, & value. need iterate on object , output form. bizarre reason it's 1 date value short.
$this->custom_from_date = new datetime(); $this->custom_to_date = new datetime(); //add 6 days in future $this->custom_to_date ->modify("+6 day"); //subtract 1 day past $this->custom_from_date->sub(new dateinterval('p1d')); //setup date interval between 2 dates $interval = new dateinterval('p1d'); $this->settodate($this->custom_to_date->format('ymd')); $this->setfromdate($this->custom_from_date->format('ymd')); //create date range object out of interval $daterange = new dateperiod($this->custom_from_date, $interval, $this->custom_to_date);
then seek iterate on date range so:
foreach ($daterange $date): ?> <th> <?= $date->format('m/d') ?><br> o: r: d: </th> <?php endforeach; ?>
it outputs:
o: r: d: 11/13 o: r: d: 11/14 o: r: d: 11/15 o: r: d: 11/16 o: r: d: 11/17 o: r: d: 11/18 o: r: d: 11/19
it returns 7 index array, not 8 expect (11/20 beingness lastly output). why be?
i understand add together 1 more day modify method, need specific dates various sql queries. share same custom date class, results not match daterange object.
php arrays datetime
No comments:
Post a Comment