I am running the following code, retrieving a list of job openings that will expire in 7 days.

$triggerDate = new DateTime();
$triggerDate->add(new DateInterval("P7D"));

$query = new EntityFieldQuery();

This is returning 0 jobs, even though I have several that will expire in 7 days. For example, one of my job nodes, has the following value

[field_expires] => Array
         [und] => Array
                 [0] => Array
                         [value] => 2013-05-09T00:00:00
                         [timezone] => America/Los_Angeles
                         [timezone_db] => America/Los_Angeles
                         [date_type] => date



When I leave the filter off altogether, the query succeeds and retrieves all items. I've tried many variations of the date format including Y-m-d\T00:00:00 and Y-m-d 00:00:00.

The field is of type: Date (ISO format). What am I doing wrong?

  • Have you tried to see in the database how is stored your field_expires ? – tostinni May 2 '13 at 22:23
  • Y-m-d\TH:i:s really should work as far as formats go. Have you tried printing $triggerDate->format('Y-m-d\TH:i:s') just to see what it is passing to the query? – rooby May 3 '13 at 10:02
  • @rooby, yes, I have and it's showing me the date I expect to see. – Robbert May 3 '13 at 15:50

This works perfectly fine:

$query = new EntityFieldQuery();
$result = $query->entityCondition('entity_type','node')
  ->entityCondition('bundle', 'product_display')
  ->propertyCondition('status', 1)
  ->fieldCondition('field_expires','value', '2013-04-30T14:02Z', '>')
|improve this answer|||||
  • Thanks for the response. However,the only problem with this is I need only those nodes from a given date, not all that come after as well, as a greater than operator would do. – Robbert May 3 '13 at 15:51
  • 1
    Then maybe try ->fieldCondition('field_expires','value', array('2013-04-30T00:00Z', '2013-04-30T11:59Z'), 'BETWEEN') – rooby May 5 '13 at 1:16
  • Maybe that is what your problem is, are you expecting that if you check for midnight it will give you all results on that day? - Because it won't, it will only give you results that are exactly midnight on the given date. You have to do a range to match the whole day. – rooby May 5 '13 at 1:18

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.