Score:0

How to change date format of exposed filter input value?

in flag

By default view exposed filter ,filtering the data in such way. http://mydomain.docksal.site/events?combine=&field_event_categories_target_id=All&field_start_date_time_value=&field_start_date_and_time_value=2023-01-07. When we inputs the date field in such format 2023-01-07

But customer wants to filter the date in dd/mm/yy When we pass the date in exposed filter in such format 07/01/2023 ,then no result found in views.

I want to filter the data in dd/mm/yy format ,below is my code.

   function goldfarb_custom_form_alter(&$form, \Drupal\Core\Form\FormStateInterface $form_state, $form_id) {
  $view_names = array('events');
  $view = $form_state->getStorage('view');
  if ($form_id == 'views_exposed_form' && in_array($view['view']->id(), $view_names)) {
    $form['#validate'][] = 'my_exposed_validate';
  }
}
function my_exposed_validate(&$form, \Drupal\Core\Form\FormStateInterface $form_state) {
  //die();
  date("Y-m-d",strtotime($form_state->getValues('field_start_date_and_time')["field_start_date_and_time_value"]));
  dump($form_state->getValues('field_start_date_and_time')["field_start_date_and_time_value"]);
}
mx flag
I tried one example and switching the date format worked for me. Are you sure everything else you're doing is correct? Are you including the time of the day correctly? Without time written out Drupal assumes it's midnight 0:00:00.
I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.