2

I'm trying to grab all Entries that were updated after a given date and time.

It seems like I can grab all entries updated after a date using the following:

{% set timeLimit = now | date_modify("-2 min") %}
{% set updated = craft.entries({ dateUpdated: '>=' ~ timeLimit }).section('myChannel') %}

The problem is, that code doesn't actually seem to take time into account at all, just date. timeLimit in the above will always return something like 2014-08-21.

1 Answer 1

2

You concatenate the strings '>=' and what is output from the timeLimit var (the same as {{ timeLimit }} does). So it gets concatenated to '>=2014-08-22'.

You need to change two things. First add a space after the comparison operator and second, change the date output to include the time by using the date filter. I suggest to use 'c' as the value for the formatting parameter, as it returns the datetime ISO 8601 formatted.

{% set timeLimit = now|date_modify('-2 min') %}

{# Get entries with `dateUpdated('>= 2014-08-22T01:55:00+02:00')` #}
{% set updated = craft.entries.dateUpdated('>= ' ~ timeLimit|date('c')) %}
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.