Welcome Guest ( Log In | Register )



 
Reply to this topicStart new topic
> Help On Date()
demolaynyc
post Jan 3 2007, 10:34 PM
Post #1


Premium Member
Group Icon

Group: Members
Posts: 330
Joined: 2-February 06
Member No.: 11,040



Hi, can someone post a source code that will display the last six months.

ie: This month is January - display December, November, October, September, August, July

I really need this urgently. Thx.
Go to the top of the page
 
+Quote Post
bluefish
post Jan 3 2007, 11:54 PM
Post #2


Member [ Level 2 ]
Group Icon

Group: Members
Posts: 71
Joined: 16-December 06
Member No.: 18,419



CODE
//Set $m to value of current month, starting index at 0
$m = date("m")-1;
//Create array of month names
$months = array(0 => "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December");

//Iterate through last six months
for($t=$m-1;$t<=$m-6;$t--) {
  //Print a comma if not first in list
  if($t!=$m-1) echo ", ";
  //Print the month name, using modulo to make sure it is a positive value
  echo $months[$t % 12];
}

That should work. Excuse me if my PHP is rusty.

This post has been edited by bluefish: Jan 3 2007, 11:57 PM
Go to the top of the page
 
+Quote Post
demolaynyc
post Jan 4 2007, 12:04 AM
Post #3


Premium Member
Group Icon

Group: Members
Posts: 330
Joined: 2-February 06
Member No.: 11,040



No matter. Thanks a lot!
Go to the top of the page
 
+Quote Post
bluefish
post Jan 4 2007, 07:08 PM
Post #4


Member [ Level 2 ]
Group Icon

Group: Members
Posts: 71
Joined: 16-December 06
Member No.: 18,419



Er, sorry, just noticed, should be $t>=$m-6, not <=.
Go to the top of the page
 
+Quote Post

Reply to this topicStart new topic

Collapse

> Similar Topics

Topics Topics
  1. Date Timezones.(2)


 



- Lo-Fi Version Time is now: 23rd November 2008 - 05:26 PM