1

I have a content type with a date field (myFieldDate) whose values are timestamps. (I'm collecting only day, month, and year.)

I have a custom form where I have a select list to select month and year. I need to use the EntityFieldQuery class to get all the nodes where the date field contains the month and the year I specified.

$query = new EntityFieldQuery();
$query
  ->entityCondition('entity_type', 'node')
  ->entityCondition('bundle', 'horas')
  ->propertyCondition('status', NODE_PUBLISHED)
  ->fieldCondition('field_day', 'value', $myFieldDate, '=');

If the select list contains '2015-05', for example, the query should return all nodes where myFieldDate contains a date for that month and year.

1 Answer 1

2

You can use a range like condition:

$query = new EntityFieldQuery();
$query
  ->entityCondition('entity_type', 'node')
  ->entityCondition('bundle', 'horas')
  ->propertyCondition('status', NODE_PUBLISHED)
  ->fieldCondition('field_day', 'value', $myFieldDate . '-01', '>=')
  ->fieldCondition('field_day', 'value', $myFieldDate . '-31', '<=');
0

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.