Skip to content

Instantly share code, notes, and snippets.

@oshanz
Created February 6, 2014 07:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save oshanz/8839750 to your computer and use it in GitHub Desktop.
Save oshanz/8839750 to your computer and use it in GitHub Desktop.
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