Skip to content
Pierre Germain edited this page Aug 14, 2019 · 3 revisions

Entity Query with dates

Get past ids

$field = 'field_name';
$now = date('Y-m-d', time());
$start = date('Y-m-d',strtotime($now.'-'.$days.' days'));

// Get past ids using entityQuery.
$ids = \Drupal::entityQuery('entity_type')
       ->condition($field, $now, '<=')
       ->execute();

// Get ids for a specific date
$ids = \Drupal::entityQuery('commerce_product_variation')
      ->condition($field, $now)
      ->execute();

// Get ids from a range of dates
$ids = \Drupal::entityQuery('commerce_product_variation')
      ->condition($field, $now, '<=')
      ->condition($field, $start, '>=')
      ->execute();

Clone this wiki locally