Jump to content

Archived

This topic is now archived and is closed to further replies.

matfish

Listing last few months

Recommended Posts

Hi,

All im trying to do is list the last 4 months like:-

June
May
April
March

Firstly my code done the first two correctly but then would continue the 2nd month down the rest of the page. My current attempt worked yesterday (still being in May) but then looking today (1st June) its messed up again, its missing May.

Iv got:


[code]// this prints the curent month
echo "<p><a href='/resources/blog_archive_view.php?arch=".date("Ym")."'>".date("F")."</a></p>";


// this should print the last 3 months
for ($m = 3; $m > 0; $m--)
{

$last4month = mktime(0, 0, 0, date("m", $last)+$m, date("d", $last),  date("Y", $last));
                
echo date("F y",$last4month);
                
}[/code]

Ideally would like to get rid of the first echo and just have it loop the last 4 months, including this (current) month.

Any ideas/point me in the right direction to a script etc.. would be appreciated!

Thanks for you time.


Share this post


Link to post
Share on other sites
[code]
for($i=0;$i<4;$i++) {
   echo $lastmonth = date("F y", mktime(0, 0, 0, date("m")-$i, date("d"),   date("Y")));
   echo "<br>";
}
[/code]

if you dont want to display current month....start loop with $i=1 instead of $i=0

hth

Share this post


Link to post
Share on other sites
Thank you! It works a treat!

Thanks for the prompt reply

;)

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.