Cannot change date input format in views exposed filter I am unable to change the date format for an exposed field in views. I am using BEF datepicker popup. I overrode the jquery settings to get it to enter a UK date in the dd-mm-yy format but because views is expecting it in mm-dd-yy form, the results of the filter are wrong.

This problem is addressed in this discussion https://www.drupal.org/node/1409120 but supposedly has been fixed for other people in Date 7.x 2.x. I am using BEF 7.x-3.0-beta4, Date 7.x-2.9-alpha1+2-dev, and Views 7.x-3.8, and the problem isn't fixed. I can't see any extra options in the view settings or in the config menu to change the date format.

The field name is field_activity_date_time and I have created a custom module with the following code, based on other stackoverflow suggestions (I don't have a max and min field, just a single date)

function hook_form_views_exposed_form_alter(&amp;$form, &amp;$form_state) {
    if($form['#id'] == 'views-exposed-form-test-page') {
       $form['field_activity_date_time']['#date_format'] = 'd/m/Y';
      }
    }
}


I have tried a number of different possibilities for the array key, such as 'activity_date_time', and 'views_field_activity_date_time', none of which worked. This date field is coming from a CiviCRM table which may be why the other suggestions haven't worked, but it feels to me more of a drupal problem than a civicrm one.



as suggested by harsh in the comments, I have used a different hook, but the problem still persists...

function HOOK_form_alter(&amp;$form, &amp;$form_state, $form_id){ 
  if ($form_id == 'views_exposed_form' &amp;&amp; $form_state['view']-&gt;name == 'test' &amp;&amp; $form_state['view']-&gt;current_display == 'page') { 
     $form['activity_date_time']['#date_format'] = 'd/m/Y';
     echo '&lt;pre&gt;';
     print_r($form);
     echo '&lt;/pre&gt;';
 }
}


This gave me the following

Array
(
    ...

    [activity_date_time] =&gt; Array
        (
            [#type] =&gt; textfield
            [#size] =&gt; 30
            [#default_value] =&gt; 
            [#attributes] =&gt; Array
                (
                    [class] =&gt; Array
                        (
                            [0] =&gt; bef-datepicker
                        )

                )

            [#date_format] =&gt; d/m/Y
        )
)
Well, I am not proud of the clunky fix but it works!

function gmcvo_date_format_views_query_alter (&amp;$view, &amp;$query){
    $newDate = DateTime::createFromFormat('Y-d-m H:i:s', $query-&gt;where[1]['conditions'][0]['value']);
    $query-&gt;where[1]['conditions'][0]['value'] = $newDate-&gt;format('Y-m-d H:i:s');
}


If someone has a better way to do this it would be great to hear it...

edited to use the new datetime object instead of strtotime