#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2012
    Posts
    15
    Rep Power
    0

    PHP Stops Producing Dates After December 31st


    Hi guys,

    I've created a booking form on my website for people to book appointments from a list of dates. I have it set to produce 120 days from the current day. It's been working fine all year but since the 120th day has hit December 31st/Jan 1st it's no longer producing the list. I can only assume this is due to it trying to look further than December in the same year - which there obviously isn't any more days in this year... So, how do I get it to start a new year, from Jan 1st..?

    Any help would be great.
    PHP Code:
    <option selected disabled value="select-date">Select a date</option>                                                         <?php           date_default_timezone_set('Europe/London');                                                                              // Start date         $date = date('l jS F');         // End date         $end_date = date('l jS F', strtotime("+120 days"));          while (strtotime($date) <= strtotime($end_date)) {          echo "<option value=\"$date\n\">$date\n</option>";          $date = date ('l jS F', strtotime("+1 days", strtotime($date)));                  }      ?>   </select>
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Jun 2009
    Posts
    676
    Rep Power
    7
    Ummm... This list they get to choose from, is it a drop-down selection? If so, I would recommend changing to a text input. If you are worried about them entering a date outside your 120 day range, there are ways to make sure this doesn't happen. Personally, I use the Datepicker offered within jQuery. This will offer a visual calendar for the individual to select a date from, as well as offer you the ability to add restrictions of the date range.

    EDIT: The calendar DOES offer better views/themes, so the others actually look alot better than the one in the example.
    Last edited by Triple_Nothing; September 30th, 2013 at 10:47 AM.
    He who knows not and knows not he knows not: he is a fool - shun him. He who knows not and knows he knows not: he is simple - teach him. He who knows and knows not he knows: he is asleep - wake him. He who knows and knows he knows: he is wise - follow him
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2012
    Posts
    15
    Rep Power
    0
    Hi thanks for you comments.

    Yes it's a dropdown list. The calendar picker is interesting. Is it possible for me to style it myself?
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Jun 2009
    Posts
    676
    Rep Power
    7
    As long as one knows his coding, he can do anything...
    He who knows not and knows not he knows not: he is a fool - shun him. He who knows not and knows he knows not: he is simple - teach him. He who knows and knows not he knows: he is asleep - wake him. He who knows and knows he knows: he is wise - follow him
  8. #5
  9. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2012
    Posts
    15
    Rep Power
    0
    Great, thank you.

IMN logo majestic logo threadwatch logo seochat tools logo