Skip to content

Instantly share code, notes, and snippets.

@kikegarcia
Last active December 25, 2015 02:19
Show Gist options
  • Save kikegarcia/6902284 to your computer and use it in GitHub Desktop.
Save kikegarcia/6902284 to your computer and use it in GitHub Desktop.
Datepicker restrict range
<script>
$(document).ready(function(){
$('#txtStartDate').datepicker({
dateFormat: 'dd/mm/yy',
onSelect: function(dateText, inst) {
var pieces = dateText.split('/');
$('#day').val(pieces[0]);
$('#month').val(pieces[1]);
$('#year').val(pieces[2]);
var date2 = $('#txtStartDate').datepicker('getDate', '+1d');
date2.setDate(date2.getDate()+15);
$('#txtEndDate').datepicker({
dateFormat: 'dd/mm/yy',
minDate: $('#txtStartDate').datepicker('getDate'),
maxDate: date2,
onSelect: function(dateText, inst) {
var firstday = new Date($('#txtStartDate').val().split('/').reverse().join(','));
var lastday = new Date($('#txtEndDate').val().split('/').reverse().join(','));
$('#totaldays').val((lastday - firstday) / 86400000);
}
});
}
});
});
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment