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. Quote Link to comment 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 Quote Link to comment 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))); } ?> Quote Link to comment 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.) Quote Link to comment 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 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.