View Full Version : Date and time validation

06-11-2008, 09:57 AM

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.


Philip M
06-11-2008, 01:13 PM
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.