Evan69 Posted November 24, 2007 Share Posted November 24, 2007 Hi, im righting a calender script in which the events need to be over a period of several dates. Dates are in format of (YYYY-MM-DD). I will have the user enter a start date and an end date, i then need a script to find all the dates inbetween the start and end. Here is the script i have to find the difference between days, unforutanetly i cant think of a way to find the dates when the years or months are different. Any help would be much appreciated. <?php //yyyy-mm-dd $start = '2007-11-01'; $end = '2007-11-05'; //the start day is $start[2] and end day is $end[2] $start = explode('-', $start); $end = explode('-', $end); for($i = $start[2]; $i <= $end[2]; $i++) { //there cant be any 1 digit numbers if(strlen($i) < 2) { $i = '0'.$i; } $dates .= $start[0].'-'.$start[1].'-'.$i.' '; } ?> Link to comment https://forums.phpfreaks.com/topic/78661-solved-find-all-dates-between-two-dates/ Share on other sites More sharing options...
Barand Posted November 24, 2007 Share Posted November 24, 2007 <?php $start = '2007-11-01'; $end = '2007-11-05'; $st = strtotime($start); $et = strtotime($end); while ($st <= $et) { echo date ('Y-m-d', $st), '<br />'; $st = strtotime ('+1 days', $st); } ?> Link to comment https://forums.phpfreaks.com/topic/78661-solved-find-all-dates-between-two-dates/#findComment-398042 Share on other sites More sharing options...
Evan69 Posted November 24, 2007 Author Share Posted November 24, 2007 wow, thank you very much, i've been stuck for an hour on this! Link to comment https://forums.phpfreaks.com/topic/78661-solved-find-all-dates-between-two-dates/#findComment-398066 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.