Jump to content

dates b/w 2 dates PLEASE HELP


mikefrederick

Recommended Posts

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

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

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. ?> 

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"); }

} 
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.