I'm new to Drupal 8. In the user registration form, i've added a Date field via manage fields in user account settings. However, I need to customize this field and change its format. I tried 'manage display' but it's not taking effect. Is there something I'm missing. (Ideally, it should look and behave just like field datetime in Drupal 8 webform)

Appreciate any help given.


1 Answer 1


You can implement template_preprocess_field() and alter the markup of the date field.

function MY_THEME_preprocess_field(&$vars) {
  if ($vars['field_name'] === 'field_custom_date_field') {
    $date_format = 'short'; // You need to provide the machine name of the format you want.
    $timestamp = strtotime($vars['element']['#items']->value);
    $markup = \Drupal::service('date.formatter')->format($timestamp, $date_format);
    $vars['items'][0]['content']['#text'] = $markup;
  • Hi, sorry i've been extremely busy, i'll test it in the coming two days and let you know, thanks Jan 21, 2020 at 14:09

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.