Querying for user's whose birthday is today plus other OR conditions We have a date field attached to the user entity.  It stores values for year, month and day, in the following format (looking at the field_date_of_birth_value column in the DB): 1987-06-08T00:00:00.

We are using EFQ and wish to return users who's birthday is today OR some other conditions on another field also attached to the user entity (field_babys_date_of_birth, which doesn't necessarily have a value for every user and has is stored in the same format as the other field).

Is there a way to compare the stored month and day with the current ones using EFQ? If not, how would you approach this problem?

Pseudocode specification

  FETCH every account where:
    date_of_birth == TODAY (month and day only)  OR
    babys_date_of_birth == TODAY + 6 MONTHS OR
    babys_date_of_birth == TODAY + 3 MONTHS
  END FETCH
  FOREACH accounts as account
    // Custom logic (always the same).
  END FOREACH


Implemented code

&lt;?php
// Fetch users whose birthday is today.
$today = new DateTime('today');
$query = new EntityFieldQuery();
$query-&gt;entityCondition('entity_type', 'user')
  -&gt;fieldCondition('field_date_of_birth', 'value', $today, '=');
$result = $query-&gt;execute();
$uids = array_keys($result['user']);
foreach ($uids as $uid) {
  $account = user_load($uid);
  // Custom logic (always the same).
}

// Fetch users where babys_date_of_birth == today + 3months.
$after_three_months = new DateTime('today + 3 months');
$after_three_months = $after_three_months-&gt;format('Y-m-d\T00:00:00');
$query = new EntityFieldQuery();
$query-&gt;entityCondition('entity_type', 'user')
  -&gt;fieldCondition('field_babys_date_of_birth', 'value', $after_three_months, '=');
$result = $query-&gt;execute();
$uids = array_keys($result['user']);
foreach ($uids as $uid) {
  $account = user_load($uid);
  // Custom logic (always the same).
}

// Fetch users where babys_date_of_birth == today + 6 months.
$after_six_months = new DateTime('today + 6 months');
$after_six_months = $after_six_months-&gt;format('Y-m-d\T00:00:00');
$query = new EntityFieldQuery();
$query-&gt;entityCondition('entity_type', 'user')
  -&gt;fieldCondition('field_babys_date_of_birth', 'value', $after_six_months, '=');
$result = $query-&gt;execute();
$uids = array_keys($result['user']);
foreach ($uids as $uid) {
  $account = user_load($uid);
  // Custom logic (always the same).
}
?&gt;


Known problems with the code:


We think it should be better to have only one query to return all the accounts, as the custom logic to be executed is the same for all of them.
The first condition should only check for month and day (excluding year).


Maybe EFQ doesn't support ORed conditions, and we should use something else?
If you want to filter in your efq, you'll have to compare strings: 

   $today = new DateTime();
   $today = $today-&gt;format('Y-m-d\T00:00:00');


Then add in your query the condition

'field_date_of_birth_value', $today, '='


I can't tell more unless you show us your code.