# [PHP] Dynamic Date List Newbie Problem

```Hi folks,

My goal was to create a dynamic date related list as follows:```
```
- take the current date (3/12/2009)
- create a new date from it which would be the *1st* of that month -
(3/1/2009)

- then create a list that shows the current and previous 11 months like:

03/1/09
02/1/09
01/1/09
12/1/08
11/1/08 etc...

--- so I did this (not fancy but was working)

\$nowts = strtotime(date("m")."/1/".date("y"));

\$m01 = date('m',\$nowts-(0))."/1/".date('y',\$nowts-(0));
\$m02 = date('m',\$nowts-(86400*30))."/1/".date('y',\$nowts-(86400*30));
\$m03 = date('m',\$nowts-(86400*60))."/1/".date('y',\$nowts-(86400*60));
\$m04 = date('m',\$nowts-(86400*90))."/1/".date('y',\$nowts-(86400*90));
\$m05 = date('m',\$nowts-(86400*120))."/1/".date('y',\$nowts-(86400*120));
\$m06 = date('m',\$nowts-(86400*150))."/1/".date('y',\$nowts-(86400*150));
\$m07 = date('m',\$nowts-(86400*180))."/1/".date('y',\$nowts-(86400*180));
\$m08 = date('m',\$nowts-(86400*210))."/1/".date('y',\$nowts-(86400*210));
\$m09 = date('m',\$nowts-(86400*240))."/1/".date('y',\$nowts-(86400*240));
\$m10 = date('m',\$nowts-(86400*270))."/1/".date('y',\$nowts-(86400*270));
\$m11 = date('m',\$nowts-(86400*300))."/1/".date('y',\$nowts-(86400*300));
\$m12 = date('m',\$nowts-(86400*330))."/1/".date('y',\$nowts-(86400*330));

PROBLEM: all was fine for the last few months but several days back the 1st
few months were wrong - like this...

03/1/09
02/1/09
12/1/08 * wrong
12/1/08
11/1/08 etc...

* I think the math went wrong because FEB had 28 days - not 30 (not sure why
just 1 month JANUARY was wrong...)
I temporarily fixed it with less than 30 day jumps like:

\$m01 = date('m',\$nowts-(0))."/1/".date('y',\$nowts-(0));
\$m02 = date('m',\$nowts-(86400*28))."/1/".date('y',\$nowts-(86400*28));
\$m03 = date('m',\$nowts-(86400*58))."/1/".date('y',\$nowts-(86400*58));
\$m04 = date('m',\$nowts-(86400*88))."/1/".date('y',\$nowts-(86400*88));
\$m05 = date('m',\$nowts-(86400*118))."/1/".date('y',\$nowts-(86400*118));
\$m06 = date('m',\$nowts-(86400*150))."/1/".date('y',\$nowts-(86400*150));
\$m07 = date('m',\$nowts-(86400*180))."/1/".date('y',\$nowts-(86400*180));

Q: Any ideas how to fix this issue? (please try to keep it simple - 'cause I
ain't no math wiz either)

--
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

```
• [PHP] Dynamic Date List Newbie Problem revDAVE