I have two datetimepickers in a form to enter the start time and end time.
The ID of the start time is startTime and that of end time is endTime.
var startTime = document.getElementById(startTime);
var endTime = document.getElementById(endTime);
if (new Date(startTime.value).getTime() > new Date(endTime.value).getTime()) {
alert(End Time should be greater than Start Time);
return false;
}
I tried to compare the start time and end time and validated that the start time should not be greater than the end time.
Now, I want to write a validation, so that the end time should aleast be greater than the start time by 1 hour.
sampleLink: DateTimePicker Example
$('#startTime').datetimepicker({
onClose: function(dateText, inst) {
var endDateTextBox = $('#endTime');
if (endDateTextBox.val() != '') {
var testStartDate = new Date(dateText);
var testEndDate = new Date(endDateTextBox.val());
if (testStartDate > testEndDate)
endDateTextBox.val(dateText);
}
else {
endDateTextBox.val(dateText);
}
},
onSelect: function (selectedDateTime){
var start = $(this).datetimepicker('getDate');
$('#endTime').datetimepicker('option', 'minDate', new Date(start.getTime()));
}
});
$('#endTime').datetimepicker({
onClose: function(dateText, inst) {
var startDateTextBox = $('#startTime');
if (startDateTextBox.val() != '') {
var testStartDate = new Date(startDateTextBox.val());
var testEndDate = new Date(dateText);
if (testStartDate > testEndDate)
startDateTextBox.val(dateText);
}
else {
startDateTextBox.val(dateText);
}
},
onSelect: function (selectedDateTime){
var end = $(this).datetimepicker('getDate');
$('#startTime').datetimepicker('option', 'maxDate', new Date(end.getTime()) );
}
});
I tried with this and got the start time and end time to be the same. But I'm not sure how to increase the end time by 1 hour.
For example, if the starttime value is 03-23-2012 10:00 AM i want the endtime as 03-23-2012 11:00 AM
Can any one help me on this please?
Thanks