note 100730 added to dateperiod.construct

From: Date: Wed, 03 Nov 2010 11:50:57 +0000
Subject: note 100730 added to dateperiod.construct
Groups: php.notes 
Request: Send a blank email to php-notes+get-173706@lists.php.net to get a copy of this message
I found two things useful to know that aren't covered here. 1. endDate is excluded: $i = new DateInterval('P1D'); $d1 = new Datetime(); $d2 = clone $d1; $d2->add($i); foreach(new DatePeriod($d1, $i, $d2) as $d) { echo $d->format('Y-m-d H:i:s') . "\n"; } Will output: 2010-11-03 12:39:53 (Another one because I got it wrong at first) 2. For the first form, recurrences really means REcurrences, not occurences. $i = new DateInterval('P1D'); $d = new Datetime(); foreach(new DatePeriod($d, $i, 1) as $d) { echo $d->format('Y-m-d H:i:s') . "\n"; } Will output: 2010-11-03 12:41:05 2010-11-04 12:41:05 ---- Server IP: 69.147.83.197 Probable Submitter: 85.180.66.116 ---- Manual Page -- http://www.php.net/manual/en/dateperiod.construct.php Edit -- https://master.php.net/note/edit/100730 Del: integrated -- https://master.php.net/note/delete/100730/integrated Del: useless -- https://master.php.net/note/delete/100730/useless Del: bad code -- https://master.php.net/note/delete/100730/bad+code Del: spam -- https://master.php.net/note/delete/100730/spam Del: non-english -- https://master.php.net/note/delete/100730/non-english Del: in docs -- https://master.php.net/note/delete/100730/in+docs Del: other reasons-- https://master.php.net/note/delete/100730 Reject -- https://master.php.net/note/reject/100730 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#173706) next »