Re: Dynamic Date List Newbie Problem

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

 



On 3/12/2009 9:39 AM, "TG" <tg-php@xxxxxxxxxxxxxxxxxxxxxx> wrote:

> $currmonth = date("m");
> 
> for ($i = 1; $i <= 11; $i++) {
>     $m[$i] = date("m/d/y"), mktime(0,0,0,$currmonth-$i, 1, 2009));
> }
> 
> Something like that.  mktime() is remarkably flexible.  If you start on
> month 3 and you subtract 5, you get month = -2.   So that would be
> -2/1/2009, which mktime will translate to 11/1/2008.
> 
> This is totally off the top of my head, but you get the idea.  Works with
> days and years too.  Sometimes it's useful when going backwards and not
> sure how many days the previous month had (without doing another call to
> find out).
> 
> -TG


SOLVED - Thanks so much Andrew & TG

>From your examples - I was able to create this working table going back 2
years - thanks again!

============

<table border="1" cellspacing="2" cellpadding="2">
  <tr>
    <td>Dates</td>
  </tr>
  <?php
$currmonth = date("m");
$curryear = date("y");
$i = 0;
do { ?>
  <tr>
    <td><?php  
    $m[$i] = date("m/d/y", mktime(0,0,0,$currmonth-$i, 1, $curryear));
echo $m[$i].'<br />';
   $i++ ?>
    </td>
  </tr>
  <?php } while ($i < 25); ?>
</table>

 


--
Thanks - RevDave
Cool @ hosting4days . com
[db-lists 09]




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


[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