mikefrederick Posted March 5, 2008 Share Posted March 5, 2008 I am making a calendar, and I have events that have upper and lower bounds. For all dates between those two dates, I want to have the event show up for that day (right now I am writing 'Y' for all dates with events). I can't get the dates between the upper and lower bound to show up with a Y. Thanks for taking a look... <?php for($i=0; $i<=30; $i++) { $lbound=$events_r[$i]["date_lbound"]; $ubound=$events_r[$i]["date_ubound"]; $explodelower[$i]=explode(" ",$events_r[$i]["date_lbound"]); $explodeupper[$i]=explode(" ",$events_r[$i]["date_ubound"]); $start = strtotime($explodelower[$i][0]); $end = strtotime($explodeupper[$i][0]); $t=0; while ($start < $end) { $eventdates[$i][$t]=date('Y-j-n', $start); $t++; $start = strtotime("{$lbound} +{$t} days"); } } //this changes correctly for each date of the year (i.e. march 1, 2008 = 2008-1-3) $newdatee=$newyear . "-".$newmonth. "-" . $date; for($r=0; $r<=30; $r++) { //HELP HERE FOR FIRST CONDITION OF IF STATEMENT IS NEEDED if($eventdates[$r]==$newdatee || $explodelower[$r][0]==$newdatee || $explodeupper[$r][0]==$newdatee) { echo 'Y'; } } ?> Link to comment https://forums.phpfreaks.com/topic/94553-dates-bw-2-dates-please-help/ Share on other sites More sharing options...
mikefrederick Posted March 5, 2008 Author Share Posted March 5, 2008 so you can see why i used explode, this is an example of a lower bound: $events[0]["date_lbound"] = "2007-11-9 7:00 PM"; Link to comment https://forums.phpfreaks.com/topic/94553-dates-bw-2-dates-please-help/#findComment-484137 Share on other sites More sharing options...
craygo Posted March 5, 2008 Share Posted March 5, 2008 strtotime doesn't seem to work well with date formatted as 2007-11-9. so when this happens your date will actually be dec 31 1969. try using preg_replace to replace the "-" with "/" $start = strtotime(preg_replace("-", "/", $explodelower[$i][0])); Ray Link to comment https://forums.phpfreaks.com/topic/94553-dates-bw-2-dates-please-help/#findComment-484142 Share on other sites More sharing options...
kenrbnsn Posted March 5, 2008 Share Posted March 5, 2008 Can you show us a sample of the $events_r array? Ken Link to comment https://forums.phpfreaks.com/topic/94553-dates-bw-2-dates-please-help/#findComment-484148 Share on other sites More sharing options...
kenrbnsn Posted March 5, 2008 Share Posted March 5, 2008 Strtottime works fine with dates like "2007-11-9" Ken Link to comment https://forums.phpfreaks.com/topic/94553-dates-bw-2-dates-please-help/#findComment-484150 Share on other sites More sharing options...
craygo Posted March 5, 2008 Share Posted March 5, 2008 Yes i noticed, I may have been thinking of something else. i know I had a problem with strtotime not working on a certain formatted date, but anyways... Ray Link to comment https://forums.phpfreaks.com/topic/94553-dates-bw-2-dates-please-help/#findComment-484153 Share on other sites More sharing options...
mikefrederick Posted March 5, 2008 Author Share Posted March 5, 2008 sure, thanks guys. Here is a strange issue: when echo $eventdates[$i][$t]; within the while loop, the dates between the lower and upperbound show up. <?php $se = new StaticEvents(); $events_r = $se->getEvents(); and from that class file: class StaticEvents { function StaticEvents() { } function getEvents() { $events = array(); $events[0]["id"] = "1194660001"; $events[0]["name"] = "Men's Retreat 1"; $events[0]["version"] = "7d5e07"; $events[0]["season"] = "Fall"; $events[0]["category"] = "Adult"; $events[0]["date_lbound"] = "2007-11-9 7:00 PM"; $events[0]["date_ubound"] = "2007-11-11 11:00 AM"; $events[0]["display"] = "False"; $events[0]["register"] = "False"; $events[0]["audience"] = ""; $events[0]["intro"] = "njoy fall in the mountain"; $events[1]["id"] = "1195264801"; $events[1]["name"] = "Mens Retreat 2"; $events[1]["version"] = "7d5e07"; $events[1]["season"] = "Fall"; $events[1]["category"] = "Adult"; $events[1]["date_lbound"] = "2007-11-16 7:00 PM"; $events[1]["date_ubound"] = "2007-11-18 11:00 AM"; $events[1]["display"] = "False"; $events[1]["register"] = "False"; $events[1]["audience"] = ""; $events[1]["intro"] = "njoy fall in the mountain"; etc. ?> Link to comment https://forums.phpfreaks.com/topic/94553-dates-bw-2-dates-please-help/#findComment-484156 Share on other sites More sharing options...
mikefrederick Posted March 5, 2008 Author Share Posted March 5, 2008 Hey there's got to be something with $t starting at zero and at the end of the while loop you add $t days. Link to comment https://forums.phpfreaks.com/topic/94553-dates-bw-2-dates-please-help/#findComment-484161 Share on other sites More sharing options...
mikefrederick Posted March 5, 2008 Author Share Posted March 5, 2008 No actually nevermind about that last comment but why isn't this working, strange. Link to comment https://forums.phpfreaks.com/topic/94553-dates-bw-2-dates-please-help/#findComment-484186 Share on other sites More sharing options...
mikefrederick Posted March 5, 2008 Author Share Posted March 5, 2008 I am using this now, changed very little from before: <?php for($i=0; $i<=30; $i++) { $lbound=$events_r[$i]["date_lbound"]; $ubound=$events_r[$i]["date_ubound"]; $explodelower[$i]=explode(" ",$events_r[$i]["date_lbound"]); $explodeupper[$i]=explode(" ",$events_r[$i]["date_ubound"]); $start = strtotime($explodelower[$i][0]); $end = strtotime($explodeupper[$i][0]); $t=0; $newdatee=$newyear . "-".$newmonth. "-" . $date; while ($start <= $end) { $eventdates[$i][$t]=date('Y-j-n', $start); if($eventdates[$i][$t]==$newdatee) { echo 'Y'; } $t++; $start = strtotime("{$explodelower[$i][0]} +{$t} days"); } } ?> Link to comment https://forums.phpfreaks.com/topic/94553-dates-bw-2-dates-please-help/#findComment-484188 Share on other sites More sharing options...
bpops Posted March 5, 2008 Share Posted March 5, 2008 Strtottime works fine with dates like "2007-11-9" Ken I've seen lots of people claim strtotime() doesn't work with that format date, but I have to agree with you. It does! I'm using it currently on a site and it works perfectly. Link to comment https://forums.phpfreaks.com/topic/94553-dates-bw-2-dates-please-help/#findComment-484195 Share on other sites More sharing options...
mikefrederick Posted March 5, 2008 Author Share Posted March 5, 2008 so stupid....I was writing $eventdates[$i][$t]=date('Y-n-j', $start); instead of: $eventdates[$i][$t]=date('Y-j-n', $start); Link to comment https://forums.phpfreaks.com/topic/94553-dates-bw-2-dates-please-help/#findComment-484201 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.