Allow to filter (in a view) on a datetime field of a custom entity I have created a custom entity as follow:
Here is an extract of my entity definition in  modules/custom/bank_operation/src/Entity/BankOperation.php
Notes:
1- As you can see, I have changed the value of the views_data key
2- The operation_date base field have the datetime type
 * @ContentEntityType(
 *   id = &quot;bank_operation&quot;,
 
 ...
 
 *     &quot;views_data&quot; = &quot;Drupal\bank_operation\BankOperationViewsData&quot;,
 
 ...
 
 
class BankOperation extends ContentEntityBase implements BankOperationInterface {

  public static function baseFieldDefinitions(EntityTypeInterface $entity_type) {

    ...
    
    $fields['operation_date'] = BaseFieldDefinition::create('datetime')
      -&gt;setLabel(t(&quot;Operation date&quot;))
      -&gt;setRequired(TRUE)
      -&gt;setSettings([
        'datetime_type' =&gt; DateTimeItem::DATETIME_TYPE_DATE,
      ])

    ...
}

Here is an extract of my overrode EntityViewsData in  modules/custom/bank_operation/src/BankOperationViewsData.php
This class is used according to the value of the views_data key. This is my attempt to allow a view to filter on the operation_date field
class BankOperationViewsData extends EntityViewsData {

  public function getViewsData() {
    $data = parent::getViewsData();
    $data['bank_operation']['operation_date']['filter'] = [
      'id' =&gt; 'datetime',
      'field' =&gt; 'operation_date',
      'table' =&gt; 'bank_operation',
      'field_name' =&gt; 'operation_date',
      'entity_type' =&gt; 'bank_operation',
    ];
    return $data;
  }

}

After that, I have created a view to display my BankOperation entities with an exposed filter on the operation_date field.
Here is the error produced when using this filter (I don't understand why ViewsYearFilterDatetime is called)
Exception: DateTime object not set. in Drupal\Component\Datetime\DateTimePlus-&gt;__call() (line 360 of core/lib/Drupal/Component/Datetime/DateTimePlus.php). 

Drupal\datetime\Plugin\views\filter\Date-&gt;opSimple() (Line: 63)
Drupal\views_year_filter\Plugin\views\filter\ViewsYearFilterDatetime-&gt;opSimple() (Line: 330)
Drupal\views\Plugin\views\filter\NumericFilter-&gt;query() (Line: 1373)
Drupal\views\ViewExecutable-&gt;_build() (Line: 1262)
Drupal\views\ViewExecutable-&gt;build() (Line: 390)
Drupal\views\Plugin\views\display\PathPluginBase-&gt;execute() (Line: 180)
Drupal\views\Plugin\views\display\Page-&gt;execute() (Line: 1630)
Drupal\views\ViewExecutable-&gt;executeDisplay() (Line: 77)

I know that there are other questions like this one, but none of them are providing a detailed answer (only links).
I have setup my question to allow people who are facing the same issue to quickly find a path to solve it.
As there are so many difficulties with base fields (sorting, displaying, filter etc in views), I decided to remove all of them and I re-created them back in the field UI.
To allow this, I set fieldable = TRUE, and field_ui_base_route = some_path in the annotations of my entity.
This is of course poor design because each field will create a table on its own but I had no time to spend on this...
Feel free to provide a better answer... I think we need a real how-to to provide the same functionalities we have for fields created in UI then for base fields
Edit to add: I have created an issue to create an help item on this topic: https://www.drupal.org/project/drupal/issues/3213021