SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Enthusiast
    Join Date
    Nov 2008
    Posts
    42
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    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
    ...

  2. #2
    SitePoint Member
    Join Date
    Apr 2011
    Posts
    17
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    If you are using php you can try the following:

    Code:
    $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!

  3. #3
    SitePoint Wizard silver trophybronze trophy Cups's Avatar
    Join Date
    Oct 2006
    Location
    France, deep rural.
    Posts
    6,869
    Mentioned
    17 Post(s)
    Tagged
    1 Thread(s)
    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?


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •