How to fetch records from entity base on only Day and month

Like In DOB need to return those user which has current day and month.


$query = \Drupal::entityQuery('user');
$query->condition('status', 1);
$query->condition('field_dob', date('m-d'));
$entity_ids = $query->execute();

In anyone have idea how to do this?

  • Have you tried with $query->where();? – Robin Mar 29 '17 at 9:14
  • or with BEWTEEN? – Robin Mar 29 '17 at 9:15
  • Hi Robin, When I try to use "where", drupal throws error. – vijay Mar 29 '17 at 9:50
  • $query->where('field_dob', date('m-d')); used this – vijay Mar 29 '17 at 9:51
  • 1
    $query= \Drupal::entityQuery('user') ->condition('field_dob','%'.date('m-d').'%', 'LIKE') ->execute(); Try this – Shreya Shetty Mar 29 '17 at 10:44

Here we are doing a LIKE query as the question stated that it wants to fetch record on basis of current month and day only not a year .

 $query= \Drupal::entityQuery('user')
     ->condition('field_dob','%'.date('m-d').'%', 'LIKE')

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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