I have a client website where people can fill out a form to rent a room on certain days. The way it works is users submit their event, the time it starts and the absolute latest time that they will be there. Then, at the end of the month I have a script that has to go through the database and collect all the events for a particular day (say January 1). Then it has to determine how to maximize the time spent in this room so the client can get the most money for rental. I know how to collect all the data and then query to get the it for a particular day. At that point I simply loop through it day by day. However, I was wondering if anyone had any experience in this. I'm looking for the fastest way to determine this without coming up with every combination of times for a day and then determining the most amount of time from these combinations. Any help on this is appreciated.