I know there are many questions asked about this topic here but no one is about the problem I have.
This script is for reservations where the user selects the date and the start and end time and makes a reservation.
I have a form with a date selector input field and two time selector input fields, one for the start time and one for the end time.
The problem is that the store which I'm writing the reservation script for is opened from 17:00 evening to 01:00 morning. So if someone is reserving from 23:00 to 01:00 the start time is always shown as bigger, which results in that the form is not validated.
Does anyone know if there is a solution to this or if there is a validator out there which can do this.
NOTE: I only want to compare the times and I don't want to add another date field.
alert('start time should be smaller')
Just subtract one hour while creating object.
var timefrom = new Date(); temp = $('#timefrom').val();.split(":"); timefrom.setHours((parseInt(temp) - 1 + 24) % 24); timefrom.setMinutes(parseInt(temp)); var timeto = new Date(); temp = $('#timeto').val().split(":"); timeto.setHours((parseInt(temp) - 1 + 24) % 24); timeto.setMinutes(parseInt(temp)); if (timeto < timefrom) alert('start time should be smaller');