How to change date format of a custom entity in an update hook? In would like to display the created date of a custom entity in the "short" format, whereas currently it displays in some default format. This is in a module that is already in, production so I need to do it as an update. I've changed the custom entity code so that it looks like this:

    $fields['created'] = BaseFieldDefinition::create('created')
      -&gt;setLabel(t('Created on'))
      -&gt;setDescription(t('When the case was created.'))
      -&gt;setDisplayOptions('view', [
        'type' =&gt; "datetime_default",
        'label' =&gt; 'above',
        'settings' =&gt; [
          'date_format' =&gt; 'short'
        ]
      ]); 


Then I ran drupal update:entities but it did not change. I was not surprised, because I had read somewhere recently (I can't find it now, sorry) that it had become obsolete &amp; custom entity updates now have to be done in update hooks.

But I am stumped as to how to update it in the update hook. I've tried this

function opencase_entities_update_8016() {
  $update_manager = \Drupal::entityDefinitionUpdateManager();
  $definition = $update_manager-&gt;getFieldStorageDefinition('created', 'oc_case');
  $update_manager-&gt;updateFieldStorageDefinition($definition);
}



... which did nothing, and then I looked at this documentation which helped me understand it's not the field storage definition that needs updating but the view config. So I made another update hook following the suggestion there, but simplifying it for my own case. I must have got it wrong because the date is still stubbornly showing in the default format. Can you help?

function opencase_entities_update_8017() {
  $update_manager = \Drupal::entityDefinitionUpdateManager();
  $field = $update_manager-&gt;getFieldStorageDefinition('created', 'oc_case');
  $properties = array(
    'targetEntityType' =&gt; $field-&gt;getTargetEntityTypeId(),
    'bundle' =&gt; $field-&gt;getTargetBundle()
  );  
  if ($view_displays = \Drupal::entityTypeManager()-&gt;getStorage('entity_view_display')-&gt;loadByProperties($properties)) {
    foreach ($view_displays as $view_display) {
      $view_display-&gt;setComponent('created', array(
        'type' =&gt; 'datetime_default',
        'settings' =&gt; ['format_type' =&gt; 'short'],
      ) + $component)-&gt;save();
    }   
  }
}




I randrush updb each time and it appeared to complete successfully. No errors in log.
When I changed base fields in the past they always updated in the plugin definitions on a cache clear. Also if this involved a schema update, by the way, which then produced a warning on the status page that there is a mismatch with the database, for which you then would need what you've described in the question.

In your case, though, my guess would be that the new settings are not valid for a timestamp field. The field formatter datetime_default is probably only working for a datetime field. 

So try to change the field formatter in the base field definition to:

    'type' =&gt; 'timestamp',