Date/Time Loop

Hello:

I am trying to create an appointment table and am having problems. I have a loading facility that I need to create an appointment book for. The theory is simple, but where I am having problems is creating a loop for adding to the table. Basically I need a to create a form where I enter the start date, start time along with end date and end time. Let’s say the facility loads every day and has hourly appointments starting at 0700 hrs and ends at 1800 hrs. I would like to enter the start date, let’s say April 01, 2011 and end date of September 1, 2011. Loop and create records of each date with the hour. Can anyone help me with this please. I have included a sample of the output in my mysql table:

tblName02
04/01/2011 07:00:00
04/01/2011 08:00:00
04/01/2011 09:00:00
04/01/2011 10:00:00
04/01/2011 11:00:00
04/01/2011 12:00:00
04/01/2011 13:00:00
04/01/2011 14:00:00
04/01/2011 15:00:00
04/01/2011 16:00:00
04/01/2011 17:00:00
04/01/2011 18:00:00

04/02/2011 07:00:00
04/02/2011 08:00:00

If you are using php you can try the following:

$start = "04/02/2011 7:00:00";
$end = "06/02/2011 7:00:00";
$hour_diff = round((strtotime($end)-strtotime($start))/3600);
for ($i = 1; $i <= $hour_diff; $i++) {
	$hours[$i] = date("m/d/Y H:i:s",strtotime("$start + $i hour"));
}

Good luck!

This sounds as if it could be a bit more complex than you are describing.

Bear in mind;

is this every day of the week or just working days?
are there any holidays to take into consideration? (annual leave, bank holidays)
lunchtimes?
exceptions ie Fridays finish at 4pm?

Also, what version of PHP are you running?