How do I get a date selector field in a content entity? I have a content entity in Drupal 8 that generates form for datetime. I just want to show only the date selector in the form, but it shows date and time selectors.

     $fields['start_date'] = BaseFieldDefinition::create('datetime')
            -&gt;setLabel(t('Start date'))
            -&gt;setDescription(t('The date that the survey is started.'))
            -&gt;setRequired(true)
            -&gt;setDisplayOptions('view', array(
                'label' =&gt; 'above',
                'type' =&gt; 'string',
                'weight' =&gt; -4,
            ))
            -&gt;setDisplayOptions('form', array(
                'type' =&gt; 'date',
                'weight' =&gt; -4,
            ))
            -&gt;setDisplayConfigurable('form', TRUE)
            -&gt;setDisplayConfigurable('view', TRUE);



  


How do I show only the date selector?
Your problem is that you are setting the option on the form and not the field.  The datatime field has an option, datetime_type which can be two strings 'date' or 'datetime' (see DateTimeItem), and it defaults to 'datetime'.

So, when you are creating your field, you need to update this setting.  The following should work for you:

$fields['start_date'] = BaseFieldDefinition::create('datetime')
  -&gt;setLabel(t('Start date'))
  -&gt;setDescription(t('The date that the survey is started.'))
  -&gt;setSetting('datetime_type', 'date')
  -&gt;setRequired(true)
  -&gt;setDisplayOptions('view', array(
    'label' =&gt; 'above',
    'type' =&gt; 'string',
    'weight' =&gt; -4,
  ))
  -&gt;setDisplayConfigurable('form', TRUE)
  -&gt;setDisplayConfigurable('view', TRUE);


As a side note, when you are having problems like this, the first place to look is at the class implementing the field that you are using, and then look at the tests that cover that field.  Often, you will find the example code that you need.  In this case, you would look at DateTimeFieldTest and see what that integration test is doing.