Last active
August 29, 2015 14:07
-
-
Save vishalbasnet23/f9e90cb07609409f8eda to your computer and use it in GitHub Desktop.
Adding suffix to day of a month jQuery datepicker(st,nd,rd)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$( "#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