4

I need to parse dates like '070126' to '26 Jan 2007'. I thought I could use the datepicker, but it gives me the an error...

$.datepicker.parseDate('ymmdd', '070126') #=> Missing number at position 6

I am starting to think that this could be a bug...

$.datepicker.parseDate('y-mm-dd', '07-01-26') #=> Fri Jan 26 2007 00:00:00 GMT+0100 (CET)

Any advice?

Thanks..

Tom Maeckelberghe
  • 1,969
  • 3
  • 21
  • 24
  • 1
    Ensure you have the latest version, as this was a bug that was fixed - https://github.com/jquery/jquery-ui/commit/a2e0eb920aaa41e6248e1a2f7d013997ba4f421f – Bob Mar 22 '11 at 12:16
  • simple whitespace error, `dateString = dateString.trim();` – Artistan Jan 29 '18 at 16:32

2 Answers2

1

Are you sure it is not working? I have no problems with your code: http://jsfiddle.net/ND2Qg/

mdrg
  • 3,242
  • 2
  • 22
  • 44
  • JQuery 1.4.4+ no problem. but i'm using JQuery 1.4.2 (http://jsfiddle.net/ND2Qg/3/)... Damn. +1 for jsfiddle.net, just love it! Thanks! – Tom Maeckelberghe Mar 22 '11 at 12:58
1

Finally i just preprocessed the date. The function add_scores() just adds '-' after each two characters.

$.datepicker.parseDate('ymmdd', add_scores('070126'));


add_scores('070126'); //=> '07-01-26'

function normalize_date(date){
        var normalized_date = [];
        $.each("ymd", function(index, format_option){
            normalized_date.push(date[index*2] + date[(index*2)+1]);
        });
        return normalized_date.toString().replace(/,/g, '-');
    }
Tom Maeckelberghe
  • 1,969
  • 3
  • 21
  • 24