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

carlcs
  • 36,220
  • 5
  • 62
  • 139
mmc501
  • 1,779
  • 13
  • 34

1 Answers1

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')) %}
carlcs
  • 36,220
  • 5
  • 62
  • 139