M
M
mletov2015-11-29 15:11:36
Drupal
mletov, 2015-11-29 15:11:36

How to filter by date in a query?

Please advise:
There is a node type with multiple date field (one node can have multiple dates).
You need to select records by date range, but it works somehow strangely.
For example:

$query->entityCondition('entity_type', 'node')
              ->entityCondition('bundle', 'performance') // ex. article
              ->propertyCondition('status', NODE_PUBLISHED)
              ->fieldCondition('field_date_perf', 'value', "2015-12-25", '>=')
              ->fieldCondition('field_date_perf', 'value', "2015-12-31", '<=')
              ->fieldOrderBy('field_date_perf', 'value', 'ASC');; // published nodes

Returns records including and for January 6, although there are no dates in the record for January 6 that fall within the range. I have already played with date formats, tried both through a dot, and through a slash and a day of a year in a different order.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question