tiota Posted July 15, 2010 Share Posted July 15, 2010 PHP vesion 5.3.0 Hi, Can anyone help me out with this code. I want to print out dates from $start_date up to $end_date but it only returns "2010-07-02" <?php $i=1; $start_date = "2010-07-01"; $end_date = "2010-07-31"; $next_date = $start_date; while($next_date <= $end_date) { $next_date = strtotime("+$i day", strtotime($start_date)); echo date("Y-m-d",$next_date); echo "<br>"; $i++; } ?> Thanks in advance. Link to comment https://forums.phpfreaks.com/topic/207788-increment-date-in-while-loop/ Share on other sites More sharing options...
dezkit Posted July 15, 2010 Share Posted July 15, 2010 $next_date = strtotime($i++." day", strtotime($start_date)); should work Link to comment https://forums.phpfreaks.com/topic/207788-increment-date-in-while-loop/#findComment-1086228 Share on other sites More sharing options...
jayesh Posted March 3, 2013 Share Posted March 3, 2013 <?php date_default_timezone_set('UTC'); $start_date = "2012-10-01"; $end_date = "2012-12-31"; $next_date = $start_date; while(strtotime($next_date) <= strtotime($end_date)) { echo "$next_date<br>"; $next_date = date ("Y-m-d", strtotime("+1 day", strtotime($next_date))); } ?> Link to comment https://forums.phpfreaks.com/topic/207788-increment-date-in-while-loop/#findComment-1416188 Share on other sites More sharing options...
teynon Posted March 3, 2013 Share Posted March 3, 2013 tiota & jayesh (thanks for helping on the post) but please remember to put your code in the code block. (Looks like a <> on the bar.) Link to comment https://forums.phpfreaks.com/topic/207788-increment-date-in-while-loop/#findComment-1416192 Share on other sites More sharing options...
Barand Posted March 3, 2013 Share Posted March 3, 2013 ... and don't resurrect 3 year old threads Link to comment https://forums.phpfreaks.com/topic/207788-increment-date-in-while-loop/#findComment-1416199 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.