March 28, 201016 yr Okay, I've had a think and I can't think of a solution to this. It would help if somebody could give me advice on what to do... Is there a way if I give PHP two times (a time in and time out) such as 09:00 and 13:30 loaded from a database I can determine whether or not a certain time is in between them two times. For example, I have a PHP script that creates a daily calendar that lists each half hour interval of the working day (starting with 09:00 and ending with 17:00). using a for loop I throw out each row and echo each time in a column so I have a table looking like: 09:00 | TABLE CELL 09:30 | TABLE CELL 10:00 | TABLE CELL (The same for every half hour time in between) 16:30 | TABLE CELL 17:00 | TABLE CELL So is there a way I can grab an event from a database that has (for example) a time in of 09:00 and a time out of 13:30 and then for each row it will determine whether or not that row is in between the event times so in our example something would happen to all the table rows from 09:00 to 13:30. Preferably these cells would be merged and I could echo out the event name in that merged cell but een if I could just echo the event name in each row it would be fine... I hope you understand.. Below is a screenshot of the calendar... http://img89.imageshack.us/img89/8360/picture1owu.png The code is below if that helps too... <?PHP $time = array("09:00", "09:30", "10:00", "10:30", "11:00", "11:30", "12:00", "12:30", "01:00", "01:30", "02:00", "02:30", "03:00", "03:30", "04:00", "04:30", "05:00"); $minremainder = date('i') % 30; $min = date('i') - $minremainder; if($min < 10) { $min = "0" . $min; } if($day = date("j") && $month = date('m')) { $now = date('h') . ":" . $min; } else { $now = "00:00"; } for($i=0;$i<17;$i++) { if($i % 2 == 1) { $odd = "bgcolor='#DDE7F2'"; } else { $odd = "bgcolor='#F8FAFC'"; } if($now == $time[$i]) { echo "<tr><th scope='row' class='now'>" . $time[$i] . "</th><td " . $odd . ">This is the current time</td></tr>"; } else { echo "<tr><th scope='row'>" . $time[$i] . "</th><td " . $odd . "> </td></tr>"; } } ?>
March 28, 201016 yr You will need to convert the times to unix timestamps (see mktime()) and then work out if the time is between the start and end time of that event
March 28, 201016 yr php allows you to compare time , first you have to convert string data type to time data type please refer this http://php.net/manual/en/function.strtotime.php it has got all the informaton
Create an account or sign in to comment