* Note this entry only pertains to the Date-Popup boxes when used in a Views filter, not a regular node-based form.
Today I needed to change the format of the date-popup box on an exposed views filter. It normally defaults to YYYY-MM-DD as shown to the left there. Most us 'merican folks don't like that much. Unfortunately, it only seems to be changeable via creating your own module.
Once you know how to create a Drupal module, just add this to it. With the below code, I reformat the date to the more familiar MM/DD/YYYY format for both the "from date" (min) and "to date" (max) values:
/** * This will change the date format on all views-exposed forms */ function YOUR_MOD_NAME_form_views_exposed_form_alter(&$form, $form_state) { $form['date_filter']['min']['#date_format'] = 'm/d/Y'; $form['date_filter']['max']['#date_format'] = 'm/d/Y'; }
As the comment says, this will change the date formatting for any view that uses these date boxes across the site, which I'm fine with. Whereas with hook_form_alter() we can target a form by incorporating the form id value into a specialized function name, all view IDs are views_exposed_form and that's just that. If you need to get more specific, you can var_dump($form) the form from within the function and glean some unique info that would allow you to target that particular form using some conditionals, again within the function.
Hope that helps someone else out! Took me a bit to figure that out - cheers.

By masslamet November 23, 2011 - 1:53 am
Greats…. it is work,
Thanks