Jump to content

Recommended Posts

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.

 

php Code:

 

$startmonth = 3;
$startyear = 2007;
$endmonth = 5;
$endyear = 2008;

 

 

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.

Link to comment
https://forums.phpfreaks.com/topic/135472-small-loop-dont-have-time-to-code-it/
Share on other sites

So you don't have time to write these five lines:

$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 />';
}

I don't know how you're going to find time to write the actual processing for each month

Well, i did actually get time to write it.. but it was way more that what you sent..

 

$startmonth = 12;
$startyear = 2007;
$endmonth = 11;
$endyear = 2010;
$completedyear = 0;

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

 

I guess you have much better php skills than i have :)

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.