I use the Form API to build forms in custom module.

Forms works fine but my custom date format is not applied.

Here is an extract of my form code :

$form['date_debut'] = array(
            '#type' => 'date',
            '#title' => $this->t('Date de début'),
            '#date_date_format' => 'd/m/Y',
            '#description' => t('Cliquez dans le champ et sélectionnez une date de début de congé dans le calendrier'),
            '#required' => TRUE

The date format is d/m/Y

But i still see Y/m/d in the input :

enter image description here

In the DOM, the date format is d/m/Y data-drupal-date-format="d/m/Y"

<input type="text" data-drupal-selector="edit-date-fin" aria-describedby="edit-date-fin--description" data-drupal-date-format="d/m/Y" class="form-date required form-control hasDatepicker" id="edit-date-fin" name="date_fin" value="" required="required" aria-required="true">

When the form is validated, i display a message with the date picker value and the date format is Y/m/d

drupal_set_message($this->t('Vous avez choisi comme date de début : @date_debut', array('@date_debut' => $form_state->getValue('date_debut'))));

See :

enter image description here

Am i missing something? How can i modify this date format visible by the user in the input and in the Drupal message ?

  • What browser are you seeing this in? This question may be a duplicate, too.
    – mpdonadio
    Commented Sep 14, 2017 at 13:10
  • @mpdonadio you’re right. I didn’t noticed that but i see this issue in Chrome OSX and not on firefox OSX. It seems to be a browser issue ? Commented Sep 14, 2017 at 13:28
  • @mpdonadio i guess it is a duplicate of this question : drupal.stackexchange.com/questions/243286/… Should i delete my question ? Commented Sep 14, 2017 at 13:39
  • Yeah, this is a HTML5 input element complication. That may not be the best question about this. I'll dig. Leave this for now, and we'll close as dup if needed. Otherwise, I will write up a proper answer.
    – mpdonadio
    Commented Sep 14, 2017 at 13:53
  • Try '#date_format' => 'd/m/Y' instead of '#date_date_format' => 'd/m/Y' Commented Sep 14, 2017 at 14:18


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.