Hello and welcome to our community! Is this your first visit?
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Jun 2008
    Thanked 0 Times in 0 Posts

    Date and time validation


    I have a problem with a date and time validation issue.

    On http://www.tapatapa.co.uk/prototype/reservation.html I have a form to request a restaurant booking.

    The validation on the time field should see if the the user is requesting a booking for the same day, if it is for the same day and the time for the booking is past 20:00 on the same day a javascript alert should notify the user to call the venue as the request is too close to the closing time.

    The day is important as a request for a booking made for a future date gives admin enough time reply to booking (more than 24hrs)

    Hopefully it makes sense, any help would be appreciated.


  • #2
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    London, England
    Thanked 2,573 Times in 2,551 Posts
    This ought to move you forward:-

    <script type = "text/javascript">
    function checkTime() {
    var bookingyear = 2008;
    var bookingmonth = 5;  // months 0-11
    var bookingdate = 11;
    var bookingtimehrs = 20;
    var today = new Date();
    var now = today.getTime();
    var d = new Date();
    d.setFullYear(bookingyear, bookingmonth, bookingdate); 
    var bookingSlot = d.getTime();
    if (bookingSlot < now) {  // not before today's date
    alert ("You cannot make a booking for a date/time  which has passed!");
    return false;
    if ((today.getFullYear() == bookingyear) && (today.getMonth() == bookingmonth) && (today.getDate() == bookingdate)) {
    if (bookingtimehrs >= 20) {
    alert ("Please call the venue as your booking is too close to closing time");
    return false;

    All advice is supplied packaged by intellectual weight, and not by volume. Contents may settle slightly in transit.


    Posting Permissions

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