I'm running into an issue where incorrect results are being returned when filtering Craft Commerce orders by date in a template. Can anyone help? I cannot figure out what is going on.
FACTS:
- Craft install is using
America/Denver
for timezone. - I'm passing dates via the query string with this format:
YYYY-mm-dd
- PHP version is 7.1.
- Problem timestamp from the DB is (2017-11-10 00:14:04)... this doesn't match the screenshot below because I've been fiddling with dates.
This is my reduced code:
{% set start = "2017-11-09" | date('Y-m-d 00:00:00', 'America/Denver') %}
{% set end = "2017-11-09" | date('Y-m-d 23:59:59', 'America/Denver') %}
{% set orders = craft.commerce.orders.dateOrdered('and', '>= ' ~ start, '<= ' ~ end).find() %}
{% for order in orders %}
{{ order.dateOrdered | date('Y-m-d H:i:s e') }}<br/>
{% endfor %}
date('Y-m-d')
is YYYY-MM-DD (zero-padded double digits for month and day), not YYYY-M-D. Not sure if that would make a difference or not, but it might affect the variables you're setting in the first two lines.2017-11-09
, correct? Or the date format character would be changed from d to j like so:date('Y-m-j')
, yes?