Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get the dateFormat from jQuery UI datepicker?

In my page, the datepicker dateFormat option is being set automatically by loading a localized .js file according to the current users's language settings. Elsewhere in the page, I need to format some dates, so I'd like to get the dateFormat option back out of the datePicker.

The jQuery documentation says you can retrieve the dateFormat option like so:

$('.selector').datepicker('option', 'dateFormat');

However, this returns a jQuery object wrapping the datePicker, not a string value as expected. Is this a bug? Is there another way to retrieve the dateValue option?

I'm using jQuery 1.3.2 and jQuery UI 1.7.1.

I know that I could simply look up the dateFormat another way, but pulling it out of the datepicker would be clean and elegant.

like image 581
ctsears Avatar asked Jun 12 '09 17:06

ctsears


People also ask

How can change date format in jQuery UI datepicker?

inside the jQuery script code just paste the code. $( ". selector" ). datepicker({ dateFormat: 'yy-mm-dd' });

How do I change date format in date picker?

Do one of the following: For a text box control or a date picker control, ensure that the Data type list displays the appropriate data type, and then click Format. For an expression box control, ensure that the Format as list displays the appropriate data type, and then click Format.

What is minDate and maxDate in jQuery datepicker?

If you like to restrict access of users to select a date within a range then there is minDate and maxDate options are available in jQuery UI. Using this you can set the date range of the Datepicker. After defining these options the other days will be disabled which are not in a defined range.


1 Answers

Using that method works for me1. Are there multiple items with the selector class? Do you know that the element has already been added as a date picker?


1 On the Date Picker demo site, type javascript:alert($("#datepicker").datepicker('option', 'dateFormat')); into the address bar, and it will give you "mm/dd/yy."
like image 178
bdukes Avatar answered Sep 23 '22 07:09

bdukes