Hi, If someone could plz code this small php code for me. I have 4 variables to represent a startdate and enddate based on month and year. $startmonth = 3; $startyear = 2007; $endmonth = 5; $endyear = 2008; PHP: I want to loop through all months from 3-2007 to 5-2008 and do some processing for each month. Can anyone help me? Just make me the loop and ill code the process inside the loop myself. Thanks in advance.
don't forget to include the year for ($i = $startyear ; $i <= $endyear; $i++){ for ($x = $startmonth; $x <= $endmonth; $x++){
yes, but we have a limit of month to be max 12.. so how do we go about ending the year at 12th month and then stating the new year at 1st month?
I managed to write this: for ($i = $startyear ; $i <= $endyear; $i++){ if($i < $endyear){$tendmonth=12;} else {$tendmonth=$endmonth;} if($completedyear == 1) {$tstartmonth=1;} else {$tstartmonth=$startmonth;} for ($x = $tstartmonth; $x <= $tendmonth; $x++){ echo $i."-".$x."<br/>"; $completedyear = 1; } } PHP: But then Mark Baker at phpfreaks helped me out and wrote this awesome code for me $startDate = mktime(0,0,0,$startmonth,1,$startyear); $endDate = mktime(0,0,0,$endmonth+1,1,$endyear); for($date = $startDate; $date < $endDate; $date = strtotime('+1 month',$date)) { echo 'Date is '.date('M-Y',$date).'<br />'; } PHP: Great Stuff !