Re: date iteration
| From: | Rabin Vincent | Date: | Tue, 23 May 2006 11:31:08 +0000 |
| Subject: | Re: date iteration | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-236703@lists.php.net to get a copy of this message | ||
On 5/23/06, Dave Goodchild <buddhamagnet@gmail.com> wrote:
Hi all, I am writing an app that runs a prize draw, wherein the admin chooses the duration by adding a start date and number of days for the draw to run. These values are passed into a small function that generates an array holding the start date, end date and all dates in between as follows: function generateDates($first, $duration) {Your mktime() usage is off. I think you're confusing it with strtotime(). Please see the function arguments in the docs: php.net/mktime php.net/strtotime Also, inside the loop, instead of using getdate and then concatenating to form the date string, consider using the date() function to do it. php.net/date Rabin -- http://rab.in$dates = array(); $date = getdate(mktime($first)); $month = $date['mon'];$day = $date['mday'];$year = $date['year'];for ($i = 1;$i <= $duration; $i++) {$added = getdate(mktime($day++ . "-" . $month . "-" . $year)); $dates[] = $added['mday'] . "-" . $added['mon'] . "-" .$added['year'];} return $dates;} $series = generateDates('23-05-2006', 20); var_dump($series); ...when I var_dump the array the iteration stops at May 24 - I am looking into it but does anyone have any ideas why this is sticking ie is my date arithmetic wrong? Cheers.