Jump to content

Looping the days of the week


bruckerrlb

Recommended Posts

I'm trying to create a loop, starting from today, until let's say 30 days down the road. The code I have now looks like

<?php
		$today = date("D M d");


			//$theday = date(
			for ($i=$today; $i<=30; $i++)
		  {
			  
		  $date = $today++;

		  ?>
              <option value="<?php echo $date; ?>"><?php echo $date;?></option>
              <?php
		  echo $date;
		  }
			?>

This just seems to be looping the number part (d) and not the M or the D, can someone show me how to do this or point me in the right direction?

 

Thanks

Link to comment
Share on other sites

$i=1;
while ($i<31) {
  if($i==1) {
    echo date('Y-m-d', strtotime("+1 days"))  . "<br>";
  }else{
   echo date('Y-m-d', strtotime("+$i days")) . "<br>";
  }
$i++;
}

I don't see the reason for having both echo lines in the above code, since essentially it will do the same with just

 

$i=1;
while ($i<31) {
    echo date('Y-m-d', strtotime("+$i days")) . "<br>";
    $i++;
}

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.