1

I'm looking for the right wildcard character to use with jquery.datepicker.parseDate() in the doc it says to use '...' for literal text and also "anything else - literal text". The problem comes when it hits the 'th', 'rd', 'nd', or 'st' that comes after the day number.

I have tried

$.datepicker.parseDate('M d... 2012', 'Jun 28th, 2012');

and it didn't work. Any suggestions?

Devin Crossman
  • 7,454
  • 11
  • 64
  • 102

1 Answers1

1

Currently you can't do this with parseDate, see Adding "st, nd, rd, th" to jquery datepicker and the following pull request to add such functionality - https://github.com/jquery/jquery-ui/pull/438.

I would recommend removing 'st', 'rd', 'nd', and 'th' from the end of the day before calling parseDate and then using this.

$.datepicker.parseDate('M dd yy', 'Jun 28th 2012');

While not ideal this will work too.

var myDate;

try {
    myDate = $.datepicker.parseDate('M ddth yy', 'Jun 28th 2012');
} catch (e) {}
try {
    myDate = $.datepicker.parseDate('M ddst yy', 'Jun 28th 2012');
} catch (e) {}
try {
    myDate = $.datepicker.parseDate('M ddrd yy', 'Jun 28th 2012');
} catch (e) {}
try {
    myDate = $.datepicker.parseDate('M ddnd yy', 'Jun 28th 2012');
} catch (e) {}
Community
  • 1
  • 1
TJ VanToll
  • 12,584
  • 4
  • 43
  • 45