Custom Condition on Query I'm trying to add a custom condition in a query:

 $today = new DrupalDateTime();
 $today = $today-&gt;format("m-d");
 $ids = Drupal::entityQuery('user')
  -&gt;condition('status', 1)
  -&gt;condition("date_format('field_birthday','%m - %d')", $today, '=')
  -&gt;execute();


Error:


  PHP message: Uncaught PHP Exception
  Drupal\Core\Entity\Query\QueryException:
  "'date_format('field_birthday','%m-%d')


Version Drupal 8.8.4

What is the best way to solve this?
You can try use hook_query_TAG_alter

...
-&gt;addTag('my_module_birtday')

/**
 * Implements hook_query_TAG_alter().
 */
function my_module_query_my_module_birtday_alter(Drupal\Core\Database\Query\AlterableInterface $query) {
  $today = new DrupalDateTime();
  $today = $today-&gt;format("m-d");
  $query-&gt;addJoin('LEFT', 'user__field_birthday', 'field_birthday', 'field_birthday.entity_id = base_table.uid');
  $expression = "DATE_FORMAT(field_birthday.field_birthday_value,'%m-%d')";
  $args = [
    ':birthday'=&gt;$today
  ];
  $query-&gt;where($expression . '=:birthday', $args);

}