Dealing with Time

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
mrvanjohnson
Forum Contributor
Posts: 137
Joined: Wed May 28, 2003 11:38 am
Location: San Diego, CA

Dealing with Time

Post by mrvanjohnson »

Can anyone point me to some tutorials on managing time with PHP/MySQL.

Specifically I am building a meeting room scheduling application for my office and I am having difficulty how to manage the time issue. Things like checking to make sure a room is open when scheduling it for a meeting. So if someone schedules a room from 12 to 1 then someone else attempts to schedule the room at 12:30, how do I have PHP check and see that time falls within the range of a time that the room is already in use?

It is a MySQL back end so would I be able to use SQL command to check this?

Any help would be greatly appreciated.
User avatar
Weirdan
Moderator
Posts: 5978
Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine

Post by Weirdan »

Code: Select all

create table shedules (datetime start, datetime end,....);

Code: Select all

//adding shedule
 //$start contains requested start time, $end - end time
$res= mysql_query("select count(*) from shedules where $end between start and end or $start between start and end");
$qres=mysql_fetch_row();
if(!$qres){
 // room is open
} else {
  // already sheduled
}
User avatar
mrvanjohnson
Forum Contributor
Posts: 137
Joined: Wed May 28, 2003 11:38 am
Location: San Diego, CA

Post by mrvanjohnson »

Beautiful, thanks Weirdan I'll give that a try.
Post Reply