The entity query is a powerful and convenient tool to query for content and config entities that have certain properties/field values/field references.
Yet, it has its limitations. Comparing two fields is not possible using the generic entity query and its condition method.
For such a task, you may need to use the more low level dynamic (select) queries and its where method. An example for your use case:
$connection = \Drupal::database();
// Query node base field table.
$query = $connection->select('node_field_data', 'n');
// Join with the `field_days` field table.
$query->leftjoin('node__field_days', 'd', 'd.entity_id = n.nid');
// Query for the node ID.
// Your condition (a day has 86400 seconds; we multiply them with
// the value of the field_days field, add them to the changed
// timestamp of the node and compare it against the current time).
$query->where('n.changed + (d.field_days_value * 86400) <= :now', [
':now' => \Drupal::time()->getCurrentTime(),
// Optional sorting.
// Fetch results.
$result = $query->execute()->fetchAllKeyed(0, 0);
Above example assumes:
- that you used a numeric field type for
field_days, so its database stored value can be multiplied with seconds without any casting,
- that the
field_days field allows one value only, so we can safely ignore field deltas when joining,
field_days is present on all nodes/bundles and has a valid value,
- that you use one language only in your site/the
field_days value is not translatable, so we can also ignore langcodes.
You may have to alter the query accordingly, if any of these assumptions is not true.