0

Possible Duplicate:
Adding “st, nd, rd, th” to jquery datepicker

I'm currently using this code:

$("input[name=date]").datepicker({ dateFormat: "dd MM" });

Which saves the date as 22 November for example. I need to put something in place that would save it as 22nd November instead.

Community
  • 1
  • 1
user1738017
  • 609
  • 2
  • 12
  • 29

1 Answers1

3

Try tbis,

$("input[name=date]").datepicker({
    dateFormat: "dd MM",
    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[name=date]").val(dateArr[0] + suffix +' '+ dateArr[1]);
    }

});

Demo: http://jsfiddle.net/nmtcj/2/

Muthu Kumaran
  • 17,682
  • 5
  • 47
  • 70