Datepicker field in CP

Hi,

I’m in the process of making my plugin fully compatible with CP.
One of the things I ran into is the datepicker, which is currently powered by jQuery (which will be removed from CP in the future).

I can change the date input field to type="date" and this looks fine in the editor.
But the date format depends on the browser language and this can differ from the one in my CP install. I read over here that the datepicker has a default format (yyyy-mm-dd). Browsers localize that format (change it into mm-dd-yyyy or dd-mm-yyyy), based on the language.

I’m using the wp_date() function to display my date value and that function requires a date format.
How can I get the date format from the datepicker, so I can use it for the wp_date() function?

Guido

How can I get the date format from the datepicker

I don’t have to, found this in the Mozilla docs:

Note: The displayed date format will differ from the actual value — the displayed date is formatted based on the locale of the user’s browser , but the parsed value is always formatted yyyy-mm-dd.

So date format for the wp_date() function must be yyyy-mm-dd and this will be localized by the browser.

1 Like

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.