Change Date format on Views BEF | Drupal 8

Change Date format on Views BEF

Submitted by editor on Mon, 08/29/2016 - 11:03

How to change the date format on views Better exposed form and jQuery date popup ?

There are several methodes.

Change date format Using custom module.

1. Create a module and use he hook hook_form_views_exposed_form_alter(&$form, &$form_state);

function mymodule_form_views_exposed_form_alter(&$form, &$form_state){
  $date_format = "d-m-Y";
  $date_fields = array(
  foreach ($date_fields as $field) {
    if (!empty($form[$field])) {
      if (!empty($form[$field]['#date_format'])) {
        $form[$field]['#date_format'] = $date_format;
      if (!empty($form[$field]['min']['#date_format'])) {
        $form[$field]['min']['#date_format'] = $date_format;
      if (!empty($form[$field]['max']['#date_format'])) {
        $form[$field]['max']['#date_format'] = $date_format;
      if (!empty($form[$field]['value']['#date_format'])) {
        $form[$field]['value']['#date_format'] = $date_format;

2. Change date popup format by JS/jQuery or by hook_js_alter(&$js)
2.1 By hook_js_alter
function mymodule_js_alter(&$js) {
  $js['settings']['data'][] = array('better_exposed_filters'=> array('bef_dateformat'=>'dd-mm-yy'));

2.2 By JS/jQuers : Add following js (How to add a javascript)
$('.bef-datepicker').datepicker({ dateFormat: 'dd-mm-yy' });


Add new comment

This question is for testing whether or not you are a human visitor and to prevent automated spam submissions.
Enter the characters shown in the image.