chasethemetal Posted December 10, 2011 Share Posted December 10, 2011 Hey all! I'm trying to loop a date count, how would I put this in a loop? $start = date('Y-m-d'); and $end = date('Y-m-d', strtotime('+30 days'));Then the output would be... 2011-12-10 2011-12-11 2011-12-12 and so forth all the way up to 30 days... I know how to count numbers up in loops, but when it comes to date's I'm getting very confused. Any references or examples would be much appreciated! Thanks! Link to comment Share on other sites More sharing options...
chasethemetal Posted December 10, 2011 Author Share Posted December 10, 2011 Spoke to soon. while (strtotime($date) <= strtotime($end_date)) {echo "$date\n";$date = date ("Y-m-d", strtotime("+1 day", strtotime($date)));} Link to comment Share on other sites More sharing options...
dsonesuk Posted December 11, 2011 Share Posted December 11, 2011 $date = mktime(0,0,0,1, 1, 2011); //set date to work to$start = date('d', $date ); //set start date from set date$end = date('t', $date ); // get total number of days in month for set month and year (including leap year)while ($start <= $end) { //loop through days of set month of set yearecho date('Y-m-d', mktime(0,0,0,date('m', $date ), $start, date('Y', $date ))).'<br />';$start++;} Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.