Jump to content

[SOLVED] Print last 6 months


fohanlon

Recommended Posts

Hi Guys,

 

I know you can get the current month using data("m");

 

How can I output the last 6 months (numeric value "m" and text representation "M") from the current month including the current month.

 

Have tried a few solutions but falling down when current month is for example 2 it should print out

 

2- Feb

1 - Jan

12 - Dec

11 - Nov

10 - Oct

9 - Sept

 

Any ideas/help would be greatly appreciated.

 

Many thanks,

 

Fergal.

Link to comment
Share on other sites

Ben

 

Thanks for this code.  Seems to be nearly there.

 

When I run it it prints:

 

11 Nov

12 Dec

01 Jan

02 Feb

03 Mar

04 Apr

 

 

However I need it to print:

 

11 Nov

10 Oct

9 Sept

8 Aug

7 July

6 Jun

 

What would I change to sort this out

 

Thanks,

 

Fergal.

 

Link to comment
Share on other sites

Hi Ben

 

Solved it as follows:

 

for($i = 0; $i<6; $i++)

{

 $time = strtotime("-$i months");

 echo date("m M", $time).'<br />';

}

 

Many thanks for your help.  Hopefully this should work for all months.  strtotime works from current timestamp if none is supplied.

 

Regards

 

Fergal.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.