Skip to content

Instantly share code, notes, and snippets.

@oshanz oshanz/js
Created Feb 6, 2014

Embed
What would you like to do?
jquery month year only
$(function() {
$('#from_date_txt').datepicker({
changeMonth: true,
changeYear: true,
showButtonPanel: true,
dateFormat: 'MM yy',
maxDate: 0,
onClose: function(dateText, inst) {
var month = $("#ui-datepicker-div .ui-datepicker-month :selected").val();
var year = $("#ui-datepicker-div .ui-datepicker-year :selected").val();
$(this).datepicker('setDate', new Date(year, month, 1));
var m = parseInt(month) + parseInt(1);
if (m < 9) {
m = '0' + m;
}
$(this).val(year + '-' + m + '-01');
}
});
$('#to_date_txt').datepicker({
changeMonth: true,
changeYear: true,
showButtonPanel: true,
dateFormat: 'MM yy',
maxDate: 0,
onClose: function(dateText, inst) {
var month = $("#ui-datepicker-div .ui-datepicker-month :selected").val();
var year = $("#ui-datepicker-div .ui-datepicker-year :selected").val();
$(this).datepicker('setDate', new Date(year, month, 1));
var m = parseInt(month) + parseInt(1);
if (m < 9) {
m = '0' + m;
}
$(this).val(year + '-' + m + '-'+new Date(year,m,0).getDate());
}
});
});
<style>
.ui-datepicker-calendar {
display: none;
}
</style>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.