PHP - Compare Overlapping Dates Times For Booking Purposes With Google Calendar Events
Hi,
I want to check entered dates and times that a user selects against my "book-off" calendar which is a Google Calendar. The dates× from Google is in the form: 2011-04-29T23:00:00.000+02:00 The dates in my booking software (ABPro) is in the form: 2011-04-29 Times in form: 23:00:00 All I want the function to return is a number other than 0 if any of the dates/times in Google feed overlap the requested date/time entered in the booking. So I add a function and get the feed from Google: Code: [Select] function checkOverlapG($calendarID, $startdate, $starttime, $enddate, $endtime){ // Create an instance of the Calendar service using an unauthenticated //HTTP client $service = new Zend_Gdata_Calendar(); //Retrieving events in order of start time $query = $service->newEventQuery(); $query->setUser('calendarID'); // Set to $query->setVisibility('private-magicCookieValue') if using MagicCookie auth $query->setVisibility('public'); $query->setProjection('full'); $query->setOrderby('starttime'); $query->setSortOrder('ascending'); //start with first event in future //seFutureevents must be commented out when using start and end times. $query->setFutureevents('true'); $query->setSingleEvents('true'); $query->setMaxResults('200'); //Guess this could be anything, but can possibly make things slower. Default 25 events //$query->setStartMin('2006-12-01'); //$query->setStartMax('2006-12-16); // setStartMax is exclusive, will not include last date. Must add +1 day. // Retrieve the event list from the calendar server try { $eventFeed = $service->getCalendarEventFeed($query); } catch (Zend_Gdata_App_Exception $e) { echo "Error: " . $e->getMessage(); return null; } Now I want to compare the dates and times and see if any of them collide or overlap. I want to add a counter, and if any of the events overlap, I want the counter to add one number. 1. the first thing I do is check if the event feed include. any events. 2. then I add a counter 3. then I run a foreach to retrieve events one at a time 4. then I change the date and time format from Google Event to match the date and time format form the booking. 5. If fullday event from google, no time information is added, so I add this 6. COMPARE DATES AND TIMES and if overlapping events --> n++; I've not gotten this code to work. Probably I'm doing something wrong, and I'm sorry but I'm completely new to this. Getting the Google Calendar data is working fine, and so is changing the format of the dates/times to be same format as request data. After that (and before, I don't know). Code: [Select] $gCount = count($eventFeed); $n = 0; if (gCount>0){ foreach($eventFeed as $event){ foreach ($event->when as $when) { //Getting rid of extra 00's and time zone info for now $startGevent = $when->startTime; $startGevent = str_replace('.000+02:00',"",$startGevent); $endGevent = $when->endTime; $endGevent = str_replace('.000+02:00',"",$endGevent); //Splitting date and time into two variables list($startDateEvent, $startTimeEvent) = split('T',$startGevent); list($endDateEvent, $endTimeEvent) = split('T',$endGevent); //Fill in the blanks if($startTimeEvent!=0) {} else{$startTimeEvent = "00:00:00";} if($endTimeEvent!=0) {} else{$endTimeEvent = "00:00:00";} //Compare dates if($startdate == $endDateEvent){ if($starttime > $endTimeEvent OR $endtime < $startTimeEvent){} else { n++; } } if($enddate == $startDateEvent){ if($endtime < $startTimeEvent OR $starttime > $endTimeEvent){} else { n++; } } } } return $n; } Similar TutorialsNot sure if I posted this in the right board: As I'm setting up a plugin to parse Google Calendar events, when they are set as All Day events, they "end" at midnight, which pushes them into the next day. So if an event is to run All Day Friday, Saturday, and Sunday, it actually shows the end date as Monday, since it's midnight. Any thoughts? Hi, at the moment, I am pulling events from my Google Calendar and showing them by calling the outputCalendarByDateRange() function below. Now would like to be able to update/Delete them <html> <head> <title>Gdata</title> </head> <body> <?php //session_start(); //ini_set('display_errors',1); //ini_set('display_startup_errors',1); //error_reporting (E_ALL); //DATES if(!isset($_REQUEST['from'])){ $newdateTimeStart = "01/01/2009"; } else { $newdateTimeStart = $_REQUEST['from']; } if(!isset($_REQUEST['to'])){ $newdateTimeEnd = "11/05/2011"; } else { $newdateTimeEnd = $_REQUEST['to']; } $startyear = substr($newdateTimeStart, 6, 4); $startmonth = substr($newdateTimeStart, 3, 2); $startday = substr($newdateTimeStart, 0, 2); $newdateTimeStart = $startyear.'-'.$startmonth.'-'.$startday; $endyear = substr($newdateTimeEnd, 6, 4); $endmonth = substr($newdateTimeEnd, 3, 2); $endday = substr($newdateTimeEnd, 0, 2); $newdateTimeEnd = $endyear.'-'.$endmonth.'-'.$endday; $dateStart = $newdateTimeStart; $dateEnd = $newdateTimeEnd; //between dates function outputCalendarByDateRange($client, $startDate='2007-05-01', $endDate='2007-08-01') { $gdataCal = new Zend_Gdata_Calendar($client); $query = $gdataCal->newEventQuery(); $query->setUser('default'); $query->setVisibility('private'); $query->setProjection('full'); $query->setOrderby('starttime'); $query->setStartMin($startDate); $query->setStartMax($endDate); $eventFeed = $gdataCal->getCalendarEventFeed($query); echo "<ul>\n"; foreach ($eventFeed as $event) { echo "\t<li>" . $event->title->text . " (" . $event->id->text . ")\n"; echo "\t\t<ul>\n"; foreach ($event->when as $when) { echo "\t\t\t<li>Starts: " . $when->startTime . "</li>\n"; } echo "\t\t</ul>\n"; echo "\t</li>\n"; } echo "</ul>\n"; } //Connect to google calendar //If you do not have access to the PHP.INI file on the remote server, you should use the following statement to set the path information for Zend framework $clientLibraryPath = 'libraries'; $oldPath = set_include_path(get_include_path() . PATH_SEPARATOR . $clientLibraryPath); // load ZEND classes require_once 'Zend/Loader.php'; Zend_Loader::loadClass('Zend_Gdata'); Zend_Loader::loadClass('Zend_Gdata_ClientLogin'); Zend_Loader::loadClass('Zend_Gdata_Calendar'); Zend_Loader::loadClass('Zend_Http_Client'); // connect to calendar service $gcal = Zend_Gdata_Calendar::AUTH_SERVICE_NAME; $user = "***"gmail.com"; //Insert your google username $pass = "***"; //Insert your Google password //$user = stripslashes($_POST['user']); //Insert your google username //$pass = stripslashes($_POST['pass']); //Insert your Google password $_SESSION['user'] = $user; $_SESSION['pass'] = $pass; $client = Zend_Gdata_ClientLogin::getHttpClient($user, $pass, $gcal); $gcal = new Zend_Gdata_Calendar($client); function createEvent ($client, Zend_GData_Calendar $gcal, $title = 'testing google calendar', $desc='this is great', $where = 'at work', $startDate = '2011-04-20', $startTime = '10:00', $endDate = '2011-04-20', $endTime = '11:00', $tzOffset = '+01') { $newEvent = $gcal->newEventEntry(); $newEvent->title = $gcal->newTitle($title); $newEvent->where = array($gcal->newWhere($where)); $newEvent->content = $gcal->newContent("$desc"); $when = $gcal->newWhen(); $when->startTime = "{$startDate}T{$startTime}:00.000{$tzOffset}:00"; $when->endTime = "{$endDate}T{$endTime}:00.000{$tzOffset}:00"; $newEvent->when = array($when); // Upload the event to the calendar server // A copy of the event as it is recorded on the server is returned $createdEvent = $gcal->insertEvent($newEvent); return $createdEvent->id->text; } echo outputCalendarByDateRange($client, "$dateStart", "$dateEnd"); ?> </body> </html> Hi all I am trying to edit a piece of code to change possible times for a booking system. This is the code I have: $count=0; for($b=$startTime;$b<$endTime;$b++){ if($count==$tempVar2){ $availability .= "</td><td align='left' valign='top'>"; } if(in_array($b,$reservedArray)){ $availability .= $b.":00 ".($b<12?"am":"pm")." - ".($b+1).":00 ".($b+1<12?"am":"pm")." - Booked.<br>"; } else { $availability .=$b.":00 ".($b<12?"am":"pm")." - ".($b+1).":15 ".($b+1<13?"am":"pm")."- <input type=\"checkbox\" value=\"".$b."\" name=\"time[]\" ><br>"; } $count++; } It gives me the following times: 09:00 am - 10:15 am 10:00 am - 11:15 am 11:00 am - 12:15 am 12:00 pm - 13:15 pm 13:00 pm - 14:15 pm 14:00 pm - 15:15 pm 15:00 pm - 16:15 pm 16:00 pm - 17:15 pm How can I change it so I can have the following times available: 10:00 am - 10:30 am 10:45 am - 11:15 am 11:30 am - 12:00 pm 12:15 pm - 12:30 pm etc... Many thanks for you help Pete. i have installed a calendar i want to extract the available id_item that are not id_state=1(booked) i want to query all the items that are not booked the dates: $fromdate=22-03-2011; $todate=25-03-2011; Code: [Select] this is bookings.php mysql_select_db($database_international, $international); $query_RsBookingIO = sprintf("SELECT * FROM `bookings` LEFT JOIN bookings_items ON bookings.id_item = bookings_items.id WHERE dateDIFF (2011-03-22, 2011-03-25) and bookings.id_state ='1' LIMIT 0 , 30 ", GetSQLValueString($colname_RsBookingIO, "int")); $RsBookingIO = mysql_query($query_RsBookingIO, $international) or die(mysql_error()); $row_RsBookingIO = mysql_fetch_assoc($RsBookingIO); <?php do { echo $row_RsBookingIO['the_date']; ?> <?php } while ($row_RsBookingIO = mysql_fetch_assoc($RsBookingIO)); ?> now when creating the searchfunction.php <?php $data = file_get_contents('http://localhost/bookings.php?fromdate=$fromdate and todate=$todate'); $fromdate = $_GET['fromdate']; $todate = $_GET['todate']; $dates = explode(' ',$data); var_dump($data); foreach($dates as $aDate) { echo $aDate; //$aDate = '\''.$aDate.'\''; if (!in_array($aDate, $dates)) { $available = true; } } return $available; ?> //tables CREATE TABLE `bookings` ( `id` int(11) NOT NULL AUTO_INCREMENT, `id_item` int(20) NOT NULL DEFAULT '0', `the_date` date NOT NULL DEFAULT '0000-00-00', `id_state` int(11) NOT NULL DEFAULT '0', `id_booking` int(10) NOT NULL DEFAULT '0', PRIMARY KEY (`id`), KEY `id_item` (`id_item`), KEY `id_state` (`id_state`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=12 ; -- -- Dumping data for table `bookings` -- INSERT INTO `bookings` VALUES(1, 2, '2011-03-22', 1, 0); INSERT INTO `bookings` VALUES(3, 2, '2011-03-23', 1, 0); INSERT INTO `bookings` VALUES(4, 2, '2011-03-24', 1, 0); INSERT INTO `bookings` VALUES(5, 2, '2011-03-25', 1, 0); INSERT INTO `bookings` VALUES(6, 2, '2011-03-26', 1, 0); INSERT INTO `bookings` VALUES(7, 3, '2011-03-23', 1, 0); INSERT INTO `bookings` VALUES(8, 3, '2011-03-24', 1, 0); INSERT INTO `bookings` VALUES(9, 3, '2011-03-25', 1, 0); INSERT INTO `bookings` VALUES(10, 3, '2011-03-26', 1, 0); INSERT INTO `bookings` VALUES(11, 3, '2011-03-27', 1, 0); CREATE TABLE `bookings_items` ( `id` int(11) NOT NULL AUTO_INCREMENT, `id_user` int(11) NOT NULL DEFAULT '1', `id_ref_external` int(11) NOT NULL COMMENT 'link to external db table', `desc_en` varchar(100) NOT NULL DEFAULT '', `desc_es` varchar(100) NOT NULL DEFAULT '', `list_order` int(11) NOT NULL DEFAULT '0', `state` tinyint(1) NOT NULL DEFAULT '1', PRIMARY KEY (`id`), KEY `id_user` (`id_user`), KEY `id_ref_external` (`id_ref_external`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=4 ; -- -- Dumping data for table `bookings_items` -- INSERT INTO `bookings_items` VALUES(1, 1, 4600, 'Suite_A', 'Suite_A', 2, 1); INSERT INTO `bookings_items` VALUES(2, 1, 4601, 'Suite_B', 'Suite_B', 2, 1); Hi, As a part of my university course final year project i have to create a room reservation system. I have found this http://www.phpjabbers.com/availability-booking-calendar/index.php Which looks perfect but i cant use that as i have to code it myself. Does anyone know of a guide that will help me build something similar? Thanks in advance Hello. I'm trying to build a site where users can book appointments with personal trainers. I want to use the free and open source jQuery Full Calendar for the look and feel of the calendar since it looks pleasant and is responsive. <link removed> I want each personal trainer to have their own calendar which will show the days that they're available. When a user clicks on an available day then they will see a list of time slots that they can book in 15 minute increments. So, for instance lets say a trainer named Mike is available on Mondays-Friday from 8am-5pm. If a user comes to his calendar they will see that certain days are not fully booked and they can click on a day. Then when they click on a day they can see time intervals like this: Mike's available time slots for Tuesday August 25, 2014: 8:00 am-9:00 am - Click here to book appointment! 8:15 am-9:15 am - Click here to book appointment! 2:00 pm - 3:00 pm - Click here to book appointment! The page above can be a separate page from the calendar, but it would need to be synced with the calendar to be able to fetch the times and days that he's available for appointments. Then when the user clicks on a day, he can book an appointment and after the trainer confirms via email then the user will receive an email confirmation that his appointment is scheduled. While it's still being confirmed though, that time slot would need to be no longer visible to other users, so that there wouldn't be multiple bookings for the same time slot, to avoid those conflicts. So, the application would need to fetch the data from MySQL and use that to display the available days. If a day is not available then the user will not be able to click on it in the calendar. Also, the trainers should be able to set their schedule which will get updated to MySQL, so the schedule is normally recurring but they should also be able to change certain days if they feel like they can or cannot work on that day. Also, the appointments will vary by time, so a training session can last 30 minutes, 1 hour, 3 hours, 1 hour and a half, etc. and that would need to be taken into account when the user books an appointment because if the trainer has a 1 hour gap between 2pm and 3pm, but the session is for 2 hours, they should not be able to book that time slot, since it wouldn't make any sense. What makes this complicated is that the appointment lengths can vary. Otherwise, if every appointment was 1 hour long I would be able to just create a table for appointment times and do a query to see if they're booked and only show the booked ones. How can I do it with variable time lengths? Any help would be greatly appreciated. Edited by mac_gyver, 16 August 2014 - 09:04 AM. removed link, not relevant to post Here's what I'm trying to do. 1. A user creates a calendar that shows which dates he's available. This calendar could showcase availability for up to a year. 2. Other users can do a search for a user that's available on a set date. For e.g. July 1st. 3. All the users available on July 1st will show up in the search results.
There is no booking for appointments involved. It simply needs to show the users available on set dates. I am wondering what's the best way to create this calendar feature? I have this code that compares date times but im not sure if its correct. if("2008-08-10 00:00:00.0" > strtotime("now")) { echo "here"; } The code echo's here, but it shouldn't because the time is less than the current time. Any ideas? hi i am am making a leave calendar ...i want to compare dates and if the matches the background will be changed . i am try to do is i got two loops first for 12 months and seconds for numbers of days in that month and i am using $num = cal_days_in_month(CAL_GREGORIAN, $Month, $cYear) this will give be numbers of days in that month... then there is a my sql query which will select that dates and other data from database .. now problem i am have is that numbers of days are not increment it show date like 2011-1-1 ,2011-1-1 and so on instead of 2011-1-1, 2011-1-2.... please help me ..here <<pre lang="xml">table > <?php for($Month=01;$Month <= 12;) { ?> <tr> <td width="18%" colspan="2"><strong><?php echo $monthNames[$Month-1]; ?></strong></td> <td width="12%" colspan="2"><strong>Division</strong></td> <?php $num = cal_days_in_month(CAL_GREGORIAN, $Month, $cYear); // 31 //$dates = date("$cYear-$Month-1"); $sql ="SELECT leave_date,leave_status,leave_comments,leave_type_id FROM `hs_hr_leave` WHERE employee_id = $emplid "; $res = mysql_query($sql); for($i=1;$i<=$num;$i++) { $dates = date("$cYear-$Month-$i"); //echo $dates."<br/>"; while ($row = mysql_fetch_row($res, MYSQL_NUM)) { $time2=date("Y-n-j",strtotime ($row[0])).'<br/>'; echo "<td bgcolor='red'>".$dates."--".$time2."</td>"; //echo "<td>".$row[1]."</td><br/>"; //echo "<td>".$row[1]."</td><br/>"; //echo "<td>".$row[2]."</td><br/>"; } echo "<td width='26' height='20px' align='center' valign='middle' >".$i."</td>"; } //echo "<br/>"; $Month++; } ?> </tr> </tabl Good Evening, I have a working knowledge or HTML/CSS and right now I am learning/reading about PHP. Currently I am looking to build a website around an events calendar, let me explain more. A user would log onto the site, submit a form (with an event), this would then be added to a calendar as well a new page for the event details. The calendar would be fully visible to an visitor to the site. I would also like the ability to add a ticker on the homepage with the latest events added. How complicated is this to implement? And what are the basic requirements? I hope this makes sense. Thanks, Cain I am working on a small project, creating a calendar based booking system which includes the following features: 1) A color coded key for Booked days, Available, Partly Booked, Off Days 2) Clickable days which open up a form with available time slots 3) When time slots selected another form which allows the user to enter details about the event and then book the day
I am using php, sql to complete the project. I am aware that there are scripts available online but i want to do this from scratch.
Stuck On The code below is for a php calendar, above is what i need to achieve. Please can someone help me on how to complete this. <?php $monthNames = Array("January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"); ?> <?php if (!isset($_REQUEST["month"])) $_REQUEST["month"] = date("n"); if (!isset($_REQUEST["year"])) $_REQUEST["year"] = date("Y"); ?> <?php $cMonth = $_REQUEST["month"]; $cYear = $_REQUEST["year"]; $prev_year = $cYear; $next_year = $cYear; $prev_month = $cMonth-1; $next_month = $cMonth+1; if ($prev_month == 0 ) { $prev_month = 12; $prev_year = $cYear - 1; } if ($next_month == 13 ) { $next_month = 1; $next_year = $cYear + 1; } ?> <table width="400" border="5" align="center"> <tr align="center"> <td bgcolor="#999999" style="color:#FFFFFF"> <table width="100%" border="0" cellspacing="0" cellpadding="0"> <tr> <td width="50%" align="left"> <a href="<?php echo $_SERVER["PHP_SELF"] . "?month=". $prev_month . "&year=" . $prev_year; ?>" style="color:#FFFFFF">Previous</a></td> <td width="50%" align="right"><a href="<?php echo $_SERVER["PHP_SELF"] . "?month=". $next_month . "&year=" . $next_year; ?>" style="color:#FFFFFF">Next</a> </td> </tr> </table> </td> </tr> <tr> <td align="center"> <table width="100%" border="2" cellpadding="2" cellspacing="2"> <tr align="center"> <td colspan="7" bgcolor="#999999" style="color:#FFFFFF"> <strong> <?php echo $monthNames[$cMonth-1].' '.$cYear; ?> </strong> </td> </tr> <tr> <td align="center" bgcolor="#999999" style="color:#FFFFFF"><strong>S</strong></td> <td align="center" bgcolor="#999999" style="color:#FFFFFF"><strong>M</strong></td> <td align="center" bgcolor="#999999" style="color:#FFFFFF"><strong>T</strong></td> <td align="center" bgcolor="#999999" style="color:#FFFFFF"><strong>W</strong></td> <td align="center" bgcolor="#999999" style="color:#FFFFFF"><strong>T</strong></td> <td align="center" bgcolor="#999999" style="color:#FFFFFF"><strong>F</strong></td> <td align="center" bgcolor="#999999" style="color:#FFFFFF"><strong>S</strong></td> </tr> <?php $timestamp = mktime(0,0,0,$cMonth,1,$cYear); $maxday = date("t",$timestamp); $thismonth = getdate ($timestamp); $startday = $thismonth['wday']; for ($i=0; $i<($maxday+$startday); $i++) { if(($i % 7) == 0 ) echo "<tr> "; if($i < $startday) echo "<td></td> "; else echo "<td align='center' valign='middle' height='20px'>". ($i - $startday + 1) . "</td> "; if(($i % 7) == 6 ) echo "</tr> "; } ?> </table> </td> </tr> </table> I want to do something like this- $days_passed = daysPassed ($last_datetime); //returns (float)number of days (6 hours returns .25 days, 12 hours returns 0.5) $last_datetime = $getCurrentTime(); I will then store $last_datetime in the database for next time. I'm a bit overwhelmed by all the different time and date functions. Does someone have ready made functions that will work here? Hi All, I'm hoping someone can help as I've got myself in a muddle on some code. Basically, the form has a date field (date moved in). If the date entered is over 3 years old, all's ok However, if the date entered is less than 3 years old, the user needs to complete a list field. The list field is essentially a repeater field with a date and address field. If the user adds a date and address and this (plus the original date) is more than 3 years combined history - happy days! If the user adds a date and address and they've still not hit 3 years history, then I need to increase the number of rows (this is handled by another function which works by incrementing a field on the form. As it stands, it works until I need another field to appear i.e. they've entered the first date, then entered a date within the list/repeater field but still not got 3 years worth. I think it's more or less there but seem to have muddled some of the logic (I think/hope!). A fresh pair of eyes would be great: Here's my code: function dateDiffInDays($date1, $date2) { # Calulating the difference in timestamps $diff = strtotime($date2) - strtotime($date1); # 1 day = 24 hours # 24 * 60 * 60 = 86400 seconds return abs(round($diff / 86400)); } add_filter( 'gform_pre_render_2', 'applicant_2_previous_address_history' ); add_filter( 'gform_pre_validation_2', 'applicant_2_previous_address_history' ); function applicant_2_previous_address_history( $form ) { #get the value from the form date input d/m/Y so need to change $get_moved_in_date = rgpost( 'input_1' ); if ( $get_moved_in_date ) { #convert the date format $moved_in_date = date_format(date_create_from_format('d/m/Y', $get_moved_in_date), 'd-m-Y'); #echo "New date format is: ".$moved_in_date. "<br/>"; } #get todays date $today = date("d-m-Y"); #echo "<h3>Today: ".$today."</h3>"; #calculate the difference in days $dateDiff = dateDiffInDays($today, $moved_in_date); #printf("<p>Difference between two dates: " . $dateDiff . " Days</p>"); #check if we moved in less than 3 years ago if ( $dateDiff < 1095 ) { #less than 3 years, so need to loop through the list fields, compare dates and tally totals days if ( $days_sum < 1095 ) { # get the input from the list $list_values = rgpost( 'input_2' ); $i = 0; #use this to get even rows only due to the way data is stored :( $sum = 0; #use this to increment the no. of rows in the list $previous = null; #use this to calc date difference between rows $days_sum = $dateDiff; #set the total number of days. Don't start at 0, start from current date - time at current residence if ( $list_values ) { foreach ( $list_values as $key => $value ){ #get even rows only if($i%2 == 0){ #$sum = $sum + 1; #increment our rows if ( $value ) { #convert the date format $additional_date = date_format(date_create_from_format('d/m/Y', $value), 'd-m-Y'); #echo "<h3>Date: ".$additional_date."</h3>"; } if ( $previous !== null ){ # if it's null, we're in the first loop #convert the date format $previous_date = date_format(date_create_from_format('d/m/Y', $previous), 'd-m-Y'); $dateDiff2 = dateDiffInDays($additional_date, $previous_date); printf("<p>Next Iteration Difference between " . $additional_date . " and " . $previous_date . " is: " . $dateDiff2 . " Days</p>"); $days_sum = $days_sum + $dateDiff2; } else { #convert the date format $dateDiff1 = dateDiffInDays($additional_date, $moved_in_date); printf("<p>1st Iteration Difference between " . $additional_date . " and " . $moved_in_date . " is: " . $dateDiff1 . " Days</p>"); $days_sum = $days_sum + $dateDiff1; } $previous = $value; # set the current value, so it will be saved for the next iteration } $i++; } #end foreach $list_values } #endif $list_values $sum = $sum + 1; #increment our rows echo "<p>Total no of days = " .$days_sum.'</p>'; } #endif $days_sum < 1095 echo '<p>Not enough days so loop through list</p>'; $flag = 'true'; } else { echo '<p>Were ok!</p>'; $flag = 'false'; } #endif $dateDiff < 1095 /* if ( $dateDiff < 1095 ) { $value = 'yes'; } else { $value = 'no'; } */ #we moved in less than 3 years ago, so get history if ( $flag == 'false' ) { return $form; } foreach ( $form['fields'] as &$field ) { if ( $field->id == 2 ) { $field->isRequired = true; } echo "<p>The sum of array element is = " .$sum.'</p>'; if ( $field->id == 3 ) { $_POST['input_3'] = $sum; } } return $form; } Thanks Hi There, I am trying to use PHP to create a calendar that only show's working days - which are monday to friday. Is there any way that PHP can return a list of the next 5 working day's dates? For example, if today is Thursday 15th Sept - could it return the numbers 15,16,19,20 and 21? Thanks Matt Does anybody know of a calendar script that can handle reoccurring events ? I want to make a calendar that shows the schedule of a teacher in a school. most classes are weekly but some are only once a month or held irregular. classes are 50 minuter or sometimes 30 minutes. Preferably I would like to set the start time and end time of a class with a precision of 10 minutes. The output should be a html page that shows the weekly schedule with the days as columns and the hours as rows. Anybody knows of something similar or something I could use as a starting point ? thanks anatak I am trying to populate my even calendar with, well, events that are stored in a mysql table. I came across the following code and modified the query to work in my case. The code used mysql_query(), but I am using mysqli_query(), and for some reason it gets to that point and dies, but mysqli_error() doesn't even run; I just get "Error1:" If I take out the query part and only build the calendar it work perfectly. Does mysqli_query() not work inside a for loop? This hit my database for every day of the month, is there a better way? I also thought about running a query to pull all results then doing array_filter() inside the for loop for each day. Does this even work? I can't seem to figure it out. Code: [Select] ..... for($list_day = '1'; $list_day <= $days_in_month; $list_day++) { if($list_day == $today && $month == $nowmonth && $year == $nowyear) { $calendar.= '<td class="calendar-day-today">'; } else { $calendar.= '<td class="calendar-day">'; } /* add in the day number */ $todaydate = $year.'-'.$month.'-'.$list_day; $calendar.= '<div class="day-number" onclick=window.location.href="viewday.php?name='.$_SESSION['username'].'&id='.$todaydate.'">'.$list_day.'</div>'; $y = 0; if(strlen($x) == '1') {$x = $y.$x; } /** QUERY THE DATABASE FOR AN ENTRY FOR THIS DAY !! IF MATCHES FOUND, PRINT THEM !! **/ $todaydate = $year.'-'.$month.'-'.$list_day; $query = "SELECT * FROM health WHERE '$todaydate' >= event_start AND '$todaydate' <= event_end"; $results = mysqli_query($dbc, $query) or die ('Error1: '.mysqli_error($dbc)); if (mysqli_num_rows($results) > '0') { while($row = mysqli_fetch_array($results)){ extract($row); ...... I am open to any other suggestions also. Thanks for the help! I'm trying to do the following PHP. I have written it in English if (today's date) => date1 AND <= date2 then {display image1} elseif (today's date) => date3 AND <= date4 then {display image2} else {display image 13} There are 24 fixed dates and 13 fixed images. I have tried using combinations of strtotime(), replacing the date value with variables, hard coding the dates within the program. I don't seem to be able to get any combination to work properly. I'm sure it's just a syntax error but I can't see it. When I've searched the web all the answers I've found relate to dates within databases but as I only have 24 dates it seems a bit of overkill. I would appreciate any pointers to the correct method I might be able to use. The dates need only a day and month as I would like this to repeat year after year. <?php $today = strtotime(date('d-m')); if (strtotime($today) >= strtotime('28-10') && strtotime($today) <= strtotime('24-11')) {echo "<div>image1</div>";} elseif (strtotime($today) >= strtotime('25-11') && strtotime($today) <= strtotime('22-12')) {echo "<div>image2</div>" ;} elseif (strtotime($today) >= strtotime('23-12') && strtotime($today) <= strtotime('24-02')) {echo "<div>image3</div>" ;} else {echo "<div>image13</div>";} ?> The result I get from this is image1 appears on the web page but I would expect image3 as today is 22-01 Thank you in advance. Andrew Hello, I am struggling here. Basically I have integrated a Google Maps API with a website to show the location of the next session. This script will take the next session and return its location, so the lat and long can be fetched from another table and fed into the API. Here is the timetable in a MySQL table: I am trying to do/say the following: * Show current session (if in progress) * Show next session. (Only to be fetched from db when the previous session has expired) * If there are no sessions left on today's date, show next session on next day with sessions. How could I write this as a PHP query in order to the fetch the location data? Thanks, George. Might anyone know a good tutorial on how I might go about doing this? I found a simple calendar script that works perfectly but now I'm trying make it so I can save an event that has a start and end date that are different then each other for reoccurring to a database then have it display correctly on the calendar when I query the database. I have no clue if I'm even going about this the right way. I haven't even started diving in to if the event was to reoccur once a week or once a month, I'm just trying to get it so it displays on the start date then displays every day until the end date. Right now I take the current day, month, year that the calendar is looping on and check it against the event day, month, year. If the current calendar day is on or after the event start date then it returns true and if the current calendar day is on or before the event end date it returns true.... so then if it returns true on both then I give it the go ahead to display on that day. What I have is: if($current_date['year'] > $event_date['year']) { $result = ($return == 'boolean') ? true : 'trail'; } else if($current_date['year'] == $event_date['year']) { if($current_date['month'] > $event_date['month']) { $result = ($return == 'boolean') ? true : 'trail'; } else if($current_date['month'] == $event_date['month']) { if($current_date['day'] > $event_date['day']) { $result = ($return == 'boolean') ? true : 'trail'; } else if($current_date['day'] == $event_date['day']) { $result = ($return == 'boolean') ? true : 'today'; } else if($current_date['day'] < $event_date['day']) { $result = false; } } else if($current_date['month'] < $event_date['month']) { $result = false; } } else if($current_date['year'] < $event_date['year']) { $result = false; } break; case 'end': if($current_date['year'] < $event_date['year']) { $result = ($return == 'boolean') ? true : 'trail'; } else if($current_date['year'] == $event_date['year']) { if($current_date['month'] < $event_date['month']) { $result = ($return == 'boolean') ? true : 'trail'; } else if($current_date['month'] == $event_date['month']) { if($current_date['day'] < $event_date['day']) { $result = ($return == 'boolean') ? true : 'trail'; } else if($current_date['day'] == $event_date['day']) { $result = ($return == 'boolean') ? true : 'today'; } else if($current_date['day'] > $event_date['day']) { $result = false; } } else if($current_date['month'] > $event_date['month']) { $result = false; } } else if($current_date['year'] > $event_date['year']) { $result = false; } |