3

I'm trying to pull entries from a database where the postDate is a specific date.

{% set today = thisyear ~ "-" ~ thismonth ~ "-" ~ day %}
{% set today = today|date('Y-m-d') %}

{% set entries = craft.entries(params).section('calendar').status('null').postDate(today|date('Y-m-d'))%}

This only gets the entry if the Time element of the Post Date is empty or 00:00 How can I correct this to pull the entries even if it has a time associated with the Post Date

2
  • mmc, did my answer work for you?
    – carlcs
    Aug 15, 2014 at 7:05
  • Yep it worked on my original solution. Thanks!!
    – mmc501
    Aug 15, 2014 at 9:47

1 Answer 1

4

This happens because you set the parameter on the ElementCriteriaModel to get entries with that specific datetime. If you omit a time when you compose a datetime with strings, you'll still get a time (00:00:00) and even a timezone set on it:

{% set myDatetime = '2014-08-12' %}

{# Print the datetime in ISO 8601 format / 2014-08-12T00:00:00+02:00 #}
{{ myDatetime|date('c') }}

This is how you set the parameter to accept datetime ranges:

{% set myDatetime = thisyear ~ '-' ~ thismonth ~ '-' ~ day %}
{% set entries = craft.entries.postDate('and', '>= ' ~ myDatetime, '< ' ~ myDatetime|date_modify('+1 day')) %}
1

Your Answer

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

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