27
votes

I'm having a problem trying to format the output on the jQuery UI datepicker.

I want the dateformat to be the 'ISO 8601' format, like explained here:

http://jqueryui.com/demos/datepicker/#date-formats

This is what my code looks like:

$.datepicker.setDefaults($.datepicker.regional['nl']);
$('.datepicker').datepicker('option', {dateFormat: 'yy-mm-dd' });
3

3 Answers

39
votes

Your option setter format is just a bit off, try this:

$('.datepicker').datepicker('option', 'dateFormat', 'yy-mm-dd');

See the options pane on that page for how to set each one in this way

when doing it globally before creating a picker, do this:

$.datepicker.setDefaults($.datepicker.regional['nl']); 
$.datepicker.setDefaults({ dateFormat: 'yy-mm-dd' });
//Later..
$('.datepicker').datepicker();

Also, make sure to include your regional file, or the $.datepicker.regional['nl'] doesn't mean anything, this needs to be included before trying to setDefaults to your regional: http://jquery-ui.googlecode.com/svn/trunk/ui/i18n/

7
votes
$( "#end_date" ).datepicker({ dateFormat: 'yy-mm-dd' });

is what works for me

0
votes

You can also use a shorter way:

$.datepicker.setDefaults(jQuery.extend(
    $.datepicker.regional['nl'],
    {
    dateFormat: 'yy-mm-dd'
    }
));