phpretard Posted March 29, 2009 Share Posted March 29, 2009 I need to display the current year + 5 more. Here is what I have... $EXPYear=date(Y); for ($i=$i; $i <= 5; $i++){ echo <option>This Year And Five More</option>; } Obviously doesn't work... Thank you! Link to comment https://forums.phpfreaks.com/topic/151599-solved-simple-date-question/ Share on other sites More sharing options...
phpretard Posted March 29, 2009 Author Share Posted March 29, 2009 Not Simple? Link to comment https://forums.phpfreaks.com/topic/151599-solved-simple-date-question/#findComment-796218 Share on other sites More sharing options...
zizzi0n Posted March 29, 2009 Share Posted March 29, 2009 How about: $fiveyears = mktime(0, 0, 0, date("m"), date("d"), date("Y")+5); Haven't tried it but its basically straight from the php.net site Link to comment https://forums.phpfreaks.com/topic/151599-solved-simple-date-question/#findComment-796222 Share on other sites More sharing options...
killah Posted March 29, 2009 Share Posted March 29, 2009 echo date('Y').' and 5 year\'s ahead = '.date('Y')+5; Link to comment https://forums.phpfreaks.com/topic/151599-solved-simple-date-question/#findComment-796223 Share on other sites More sharing options...
phpretard Posted March 29, 2009 Author Share Posted March 29, 2009 Thank you $EXPYear=date(Y); $Years5=date('Y', mktime(0, 0, 0, 60, 32, $EXPYear)); for ($i=$EXPYear; $i <= $Years5; $i++){ echo "<option>$i</option>"; } Link to comment https://forums.phpfreaks.com/topic/151599-solved-simple-date-question/#findComment-796225 Share on other sites More sharing options...
Salkcin Posted March 29, 2009 Share Posted March 29, 2009 or you could simply do like this, for ($i=date('Y'); $i < (date('Y') + 5); $i++) { echo "<option>$i</option>"; } Link to comment https://forums.phpfreaks.com/topic/151599-solved-simple-date-question/#findComment-796249 Share on other sites More sharing options...
killah Posted March 29, 2009 Share Posted March 29, 2009 Pre-increment is alway's better i think. for($i = date('Y'); $i <= (date('Y') + 5); ++$i) { echo '<option value="'.$i.'">'.$i.'</option>; } Link to comment https://forums.phpfreaks.com/topic/151599-solved-simple-date-question/#findComment-796258 Share on other sites More sharing options...
PFMaBiSmAd Posted March 29, 2009 Share Posted March 29, 2009 Calling functions in the for() statement to get fixed starting and ending values, results in the slowest execution time. Link to comment https://forums.phpfreaks.com/topic/151599-solved-simple-date-question/#findComment-796261 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.