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'; } } ?> Quote Link to comment 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"; Quote Link to comment 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 Quote Link to comment 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 Quote Link to comment 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 Quote Link to comment 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 Quote Link to comment 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. ?> Quote Link to comment 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. Quote Link to comment 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. Quote Link to comment 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"); } } ?> Quote Link to comment 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. Quote Link to comment 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); 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.