bruckerrlb Posted May 3, 2010 Share Posted May 3, 2010 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 https://forums.phpfreaks.com/topic/200579-looping-the-days-of-the-week/ Share on other sites More sharing options...
JAY6390 Posted May 3, 2010 Share Posted May 3, 2010 $days = 0; $maxdays = 30; while($days < $maxdays) { echo date('D m d', time() + $days * 86400).'<br />'; $days++; } Link to comment https://forums.phpfreaks.com/topic/200579-looping-the-days-of-the-week/#findComment-1052530 Share on other sites More sharing options...
litebearer Posted May 3, 2010 Share Posted May 3, 2010 Grrrr I typpe too slow $i=1; while ($i<31) { echo date('Y-m-d', strtotime("+$i days")) . "<br>"; $i++; } Link to comment https://forums.phpfreaks.com/topic/200579-looping-the-days-of-the-week/#findComment-1052537 Share on other sites More sharing options...
JAY6390 Posted May 3, 2010 Share Posted May 3, 2010 $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 https://forums.phpfreaks.com/topic/200579-looping-the-days-of-the-week/#findComment-1052540 Share on other sites More sharing options...
bruckerrlb Posted May 3, 2010 Author Share Posted May 3, 2010 that's great, exactly what I was looking for, thanks! Link to comment https://forums.phpfreaks.com/topic/200579-looping-the-days-of-the-week/#findComment-1052549 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.