Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save vishalbasnet23/f9e90cb07609409f8eda to your computer and use it in GitHub Desktop.
Save vishalbasnet23/f9e90cb07609409f8eda to your computer and use it in GitHub Desktop.
Adding suffix to day of a month jQuery datepicker(st,nd,rd)
$( "#dateID" ).datepicker({
dateFormat: 'D M d',
onSelect: function(dateText, inst) {
var dateArr = dateText.split(' ')
var suffix = "";
switch(inst.selectedDay) {
case '1': case '21': case '31': suffix = 'st'; break;
case '2': case '22': suffix = 'nd'; break;
case '3': case '23': suffix = 'rd'; break;
default: suffix = 'th';
}
$("input#dateID").val(dateArr[0] +' '+ dateArr[1] +' '+dateArr[2]+suffix );
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment