PHP - Working With Dates And Times
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 Similar TutorialsHello, 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. 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; } I need to do some reporting and I need some help. The reporting periods are as follows: 08/28-09/03 09/04-09/10 09/11-09/17 09/18-09/24 09/25-10/01 So, they are Sunday through Saturday throughout each month. Say the date is Sept. 7.... How can I find out the date of the Sunday before last. How can I know what month I am reporting for? I am querying the database each Wed. for sales data from the previous month. I want to take the totals from my query and store them in a separate table. The problem is, I don't know how to find out what month the previous week falls into. And I don't know how to find the date of the Sunday before last. Thanks, Jake Hi all What is the best way to work with times that are stored without there date but with only one date field regarding both times? Thanks Hello all, I'm collecting date/time information via a form and would like to convert the info into something that I can stick in my MySql database (a timestamp???). I'm collecting the current month (variable name: month-- of the form "mm"), day (variable name: day -- of the form "dd"), year (variable name: year -- of the form "yyyy"), time of day (variable name: time -- of the form "h:00"), and before or after noon (variable name: ampm -- of the form "am" or "pm"). Any suggestions as to how to change this into a quantity that I can store as a value and then use to compare to other date/times would be appreciated. Thanks! Hi All, I need to subtract dates and display the number of days left. I have a 'Start' date and an 'End' date in DATETIME format in the DB. Not quite sure where to start. A simply start - end doesn't work . Start = 2011-11-01-00:00:00 End = 2011-11-30-23:59:59 Since it is now 2011-11-27, my output should equal 3. Any help is appreciated. Hi guys, I am trying to do a multidates events availability calender. The script below indicates todays date by highlighting an orange colour and also indicates the start and end date of the event highlighting grey colour on the two dates (The colour are link via css classes as shown). Code: [Select] //Today's date $todaysDate = date("d/m/Y"); $dateToCompare = $daystring . '/' . $monthstring . '/' . $year; echo "<td align='center' "; if($todaysDate == $dateToCompare){ echo "class='today'"; }else{ //Compare's the event dates $sqlcount = "select event_start,event_end from b_calender where event_start ='".$dateToCompare."' AND event_end='".$dateToCompare."'"; $noOfEvent = mysql_num_rows(mysql_query($sqlcount)); if($noOfEvent >= 1){ echo "class='event'"; } } It works ok i.e. if start date = 01/01/2012 and end date = 04/01/2012 both date will be highlighted with grey colour. However I want it to also highlight grey on the dates between the 1st and 4th to show that then anydates between the 1st and 4th are not available and this is when I'm stuck. Please guys I need help. Thanks Hello All, I have tried to find a solution for this issue for days. The script was working fine until yesterday when all of a sudden I get this warning. Quote Warning: imagecreatefrompng(http://domain.com/images/broadcast1.png) [function.imagecreatefrompng]: failed to open stream: Connection timed out in /home/domain/public_html/logo/logo1.php on line 8 line 8 is: $image_1 = imagecreatefrompng($file_1); Where $file_1 = "http://domain.com/images/broadcast1.png"; The exact code is working perfectly fine in a different server I have, both servers are running Centos with PHP5 + GD fully enabled. The image http://domain.com/images/broadcast1.png (~5Kb) is loading very fast when open through a browser. Please please help me resolve this, I have tried many different things and even uninstall and install GD again but n luck. Thank you so much for your help. I need help with a query.
I've got a table that stores references to calls that come in to our office. It has a datetime field, and for the purposes of the query, it's the only thing in this table that is important.
I've got another table that stores appointment information. The appointment start time is also a datetime field. For this query, this start time is the only thing in this table that is important.
I need to know how many times in the last year there was a day when we had at least 150 calls come in and made at least 1 appointment.
SELECT COUNT(*) FROM appointments a LEFT JOIN ( SELECT DATE(time) FROM calls WHERE <there are at least 150 calls on a day> ) c ON DATE(a.start_time) = c.time WHERE a.start_time >= CURDATE() - INTERVAL 1 YEARTo make things difficult, I guess the time would have to be converted to a day, because I'm looking for all days where there was an appointment, and the datetime field is too specific. I've been looking online for 30 mins or so, and was hoping somebody here could point me in the right direction. I'm not making much progress by myself. Edited by sKunKbad, 06 October 2014 - 01:17 PM. Hello friends, i'm getting error due to using an function for 3 times in same time if i've 3 results and i want to base36_encode the 3 output it only encode one and then gives me error Cannot redeclare base36_encode() (previously declared) here is the code // this is the encode function // function base36_encode($base10){ return base_convert($base10,10,36); } // i'm getting output here as 3 times (id) // $id = base36_encode($line[id]); echo "$id<br>"; the out but should be like this id1 id2 id3 all have been base36 encoded but it only show the 1st one id1 and the rest gives me the error above... so how can i make it works for all results not only the 1st one thanks everybody 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. Hi everyone, I'm trying to add up the current time with a specified amount of seconds and insert it in a database afterwards. When I add say: 500 seconds to the current time it adds a whole lot more and I get a number few thousands higher than I want. Can anyone help me???. Gr Ryflex I only see one "mysql_query($memberquery);" Yet the record is inserted 4 times when I check the db. Anyone see why? Thank you for your time! Code: [Select] <?php $link_register = 1; session_start(user); include("header.php"); $firstname = $_SESSION['firstname']; $middleinitial = $_SESSION['middleinitial']; $lastname = $_SESSION['lastname']; $phone = $_SESSION['phone']; $email = $_SESSION['email']; $street = $_SESSION['street']; $city = $_SESSION['city']; $state = $_SESSION['state']; $categoryArray = $_SESSION['categoryArray']; $gender = $_SESSION['gender']; $con = mysql_connect("localhost", "root", ""); if (!$con) { die("Could not connect: ". mysql_error()); } //The database is selected with the mysql_select_db() function. mysql_select_db("hobbyclub", $con); //put the data insert into a varaible so it can be checked later $memberquery = "INSERT INTO member (firstname, middleinitial, lastname, phone, email, street, city, state, gender) VALUES ('$firstname', '$middleinitial', '$lastname', '$phone', '$email', '$street', '$city', '$state', '$gender')"; // if ($categoryArray){ // foreach ($categoryArray as $category){ // $categoryString .= "'$".$category."',"; // } // } // $categoryquery = "INSERT INTO category (categoryname) VALUES('$categoryString')"; // $categoryquery = "INSERT INTO category (categoryname) VALUES(".$categoryString.")"; //insert the data mysql_query($memberquery); ?> The commented out block of code is just me trying to figure out how to insert an array into the db. I have a string, and I have a variable $var = 5; $str = '<img src="img.jpg" />'; i want to display a $str (the image) $var amount of times (5). how can I do this? I've simply set some sessions.... $_SESSION['LoggedIn'] = 1; $_SESSION['UserID'] = $row["UserID"]; They don't seem to last very long, usually when I close my browser and go back on later, they'll expire. I want them to last permanently unless the user logs out. How do I do this? Thanks in advance. Hello, I am having a heck of a time trying to get time right on my website lol When a user logs in, they select what timezone they are in (UTC -1,-2,-3,-4,-5,-6....) Now this is great an all, but with daylight savings time my times are off by one hour in either direction. How do sites like this get times to work for users so easily? Thanks! weee Hi guys, i got the following code i wrote which displays a small pop up on screen if the user has mail, and display a little icon. The problem is it displays a new icon for each new mail message. How can i make it so it only display 1 icon no matter how many unread mail the user has. Or even better if not too complicated display a number next too the image? Code: [Select] <? require'xxxxxxxxxxxxxxxxx.php'; mysql_select_db("membership") or die( "Unable to select database"); $sql=("SELECT * FROM user_alerts WHERE user_id = '".($_SESSION['user_id'])."'") or die (mysql_error()); if ($query=@mysql_query($sql)) { if (mysql_num_rows($query) > 0) { while ($req=mysql_fetch_array($query)) { if ($req['messageRead'] == 'NO') { ?> <div> <img src="xxxxxxxxxxxxxx.png" width="32" height="32" alt="unread mail" /> <a href="http://www.xxxxxxxxxxxx/account=account">You have Mail!</a> <div id="boxes"> <div style="top: 199.5px; left: 551.5px; display: none;" id="dialog" class="window"> <h2>You have new mail!</h2> <br /> <p>Visit your account page to read it.</p> <br> <a href="#" class="close">Close Window</a> </div> <!-- Mask to cover the whole screen --> <div style="width: 1478px; height: 602px; display: none; opacity: 0.8;" id="mask"></div> </div> </div> <? } } } } You can ignore most of the div stuff but that's pretty much it. It should check my database for any entries with the users session id in the column called 'user_id'. and only show the image if it then finds an entry with 'NO' in the 'messageRead' column. It currently shows the images for each entry it finds. Thanks for any help hello,
i have an event reservation system. i need to make sure that every time someone is booking a new time, it's not overlap another reservation.
for example lets say i have an event reserved starting at X and ending at Y
X = Wed Sep 10 2014 07:30:00 GMT+0000 Y = Wed Sep 10 2014 08:00:00 GMT+0000and now im reserving a new event start = Wed Sep 10 2014 09:30:00 GMT+0000 end = Wed Sep 10 2014 09:30:00 GMT+0000how can i check if they are not crushing? lets say the first event starts at 12:00 and end 14:00, i need to make sure that the new event is not held between these hours. it need to be started and end before 12:00 or after 14:00. thanks in advance! Is there a way to put the value of every 15mins into an array starting and finishing at 2 var times $time1=10.00am $time2=1.30pm $timearray=array($time1, and every 15min interval up to but not including $time2) eg $timearray=array(10.00am,10.15am,10.30am..........1.15pm) Are either of these OK depending on circumstance or stupid things I should never do? Is one or the other sensible/idiotic? Is there an obvious 'better' way?
I think all the php tags opening and closing within the DIVs is untidy but it's static HTML therefore if there's a LOT of it it's easier on the server right/wrong? On the other hand, maybe all the open/close of php tags defeats the object. I'm applying for a web design apprenticeship (I know, I need one) so I'm trying to appear less stupid as much as make nice php. Many thanks in advance, I know I'll end up better off by asking here <?php // php in here ?> <div class='content header'> <?php include("includes/header.php"); ?> </div> <div class='content content1'> <?php include("includes/intro.php"); ?> </div> <div class='content content2'> <?php include("includes/quals.php"); ?> </div> <div class='content content3'> <?php include("includes/experience.php"); ?> </div> <div class='content content4'> <?php include("includes/hobbies-and-interests.php"); ?> </div> <?php // More php here ?>Or this one: <?php print("<div class='content header'>"); include("includes/header.php"); print("</div> \r\n <div class='content content1'>"); include("includes/intro.php"); print("</div> \r\n <div class='content content2'>"); include("includes/quals.php"); print("</div> \r\n <div class='content content3'>"); include("includes/experience.php"); print("</div> \r\n <div class='content content4'>"); include("includes/hobbies-and-interests.php"); print("</div> \r\n"); ?>test.zip 1.5KB 0 downloads |