Jquery Ui date time picker
I am using jquery date time picker and using start date
and end date
.
When choosing the same date for start date
and end date
I don't want the time to end date
be less start date
. How do I customize my code?
$( "#fdate" ).datetimepicker({
dateFormat: 'yy-mm-dd',timeFormat: 'HH:mm:ss',
onClose: function( selectedDate ) {
$( "#tdate" ).datetimepicker( "option", "minDate", selectedDate );
}
}).attr('readonly', 'readonly');
$( "#tdate" ).datetimepicker({dateFormat: 'yy-mm-dd',timeFormat: 'HH:mm:ss',
onClose: function( selectedDate ) {
$( "#fdate" ).datetimepicker( "option", "maxDate", selectedDate );
}
}).attr('readonly', 'readonly');
});
here fdate is start date and date is end date and fiddle of issue
source to share
You need to use the setOptions method for each timepicker:
$(document).ready(function(){
$("#fdate" ).datetimepicker({
dateFormat: 'yy-mm-dd',
timeFormat: 'HH:mm:ss',
onShow: function () {
this.setOptions({
maxDate:$('#tdate').val()?$('#tdate').val():false,
maxTime:$('#tdate').val()?$('#tdate').val():false
});
}
}).attr('readonly', 'readonly');
$( "#tdate" ).datetimepicker({
dateFormat: 'yy-mm-dd',
timeFormat: 'HH:mm:ss',
onShow: function () {
this.setOptions({
minDate:$('#fdate').val()?$('#fdate').val():false,
minTime:$('#fdate').val()?$('#fdate').val():false
});
}
}).attr('readonly', 'readonly');
Here is the Modified script .
It's not perfect, but it will bring you closer, you may need to handle some formatting. I used the onShow event, but you can easily do that in onClose too. On the official page
source to share