k0z Posted July 1, 2010 Share Posted July 1, 2010 If I have two dates, e.g.: June 24th, July 2nd and i want to range between the values, would would be the easiest way to accomplish this? Obviously range(24,2) would not return the correct array. The correct values SHOULD be: array(24,25,26,27,28,29,30,1,2); Because different months have different lengths, this could pose an issue. E.g.: Feb 27, March 2nd should return: array(27,28,1,2); What would the easiest way to accomplish this be? Thanks. Quote Link to comment https://forums.phpfreaks.com/topic/206353-custom-range-question/ Share on other sites More sharing options...
PFMaBiSmAd Posted July 1, 2010 Share Posted July 1, 2010 This gives the actual dates in that range, you can modify it as needed to get just the day number - <?php $start = 'June 24th 2010'; $end = 'July 2nd 2010'; $current_date = date('Y-m-d',strtotime($start)); $end_date = date('Y-m-d',strtotime($end)); $array = array(); // an array for the dates while($current_date <= $end_date){ $array[] = $current_date; $current_date = date('Y-m-d',strtotime($current_date . '+ 1 day')); } echo "<pre>",print_r($array,true),"</pre>"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/206353-custom-range-question/#findComment-1079468 Share on other sites More sharing options...
k0z Posted July 1, 2010 Author Share Posted July 1, 2010 This gives the actual dates in that range, you can modify it as needed to get just the day number - <?php $start = 'June 24th 2010'; $end = 'July 2nd 2010'; $current_date = date('Y-m-d',strtotime($start)); $end_date = date('Y-m-d',strtotime($end)); $array = array(); // an array for the dates while($current_date <= $end_date){ $array[] = $current_date; $current_date = date('Y-m-d',strtotime($current_date . '+ 1 day')); } echo "<pre>",print_r($array,true),"</pre>"; ?> Perfect! changed to: $start = 'June 24th 2010'; $end = 'July 2nd 2010'; $current_date = date('Y-m-d',strtotime($start)); $end_date = date('Y-m-d',strtotime($end)); $array = array(); // an array for the dates while($current_date <= $end_date){ $array[] = date('j',strtotime($current_date)); $current_date = date('Y-m-d',strtotime($current_date . '+ 1 day')); } echo "<pre>",print_r($array,true),"</pre>"; And working nicely. Thanks for your help. Quote Link to comment https://forums.phpfreaks.com/topic/206353-custom-range-question/#findComment-1079475 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.