<pre><code>'&gt;= ' ~ dateFrom|date('c')
</code></pre>

<p>is correct to output the DateTime object as a string with the time (and timezone) included. If you don’t use the filter it’s output in the <code>Y-m-d</code> format by default.</p>

<p>So my recommendation would be to double check what <code>dateFrom|date('c')</code> actually outputs and to compare it with the <code>dateOrdered</code> values in the CP or database.</p>

CC BY-SA 3.0
2017-10-13T19:39:28.617Z
Thanks a lot, of course `'>= ' ~ dateFrom|date('c')` works perfectly fine.. I didn't get any output before, because (i think) the database time is UTC and  crafts dates are UTC+2. So I ended up taking the offset into account by doing this:
`{% set dateFrom = now|date_modify( ((now|date("Z") + 3600)  * (-1)) ~' seconds') %}` and `.dateOrdered( '>= ' ~ dateFrom|date('c'))`
alex_craze
CC BY-SA 3.0
2017-10-14T06:16:36.693Z
Something isn’t right, you should not need to factor in any timezone differences.
carlcs
CC BY-SA 3.0
2017-10-21T12:53:03.783Z
sry, for my late reply. there is indeed something odd going on between our DB and craft - but as this behavior only occurs on the dev-environment I am just going to ignore this for now. Anyways, the original question was answered perfectly! thx alot.
alex_craze
CC BY-SA 3.0
2017-10-13T11:31:32.363Z
2017-10-13T11:31:32.363Z
carlcs
<p>How can I query all completed orders within the last hour? It seems craft is only comparing a date by <code>YYYY-MM-DD</code>.</p>

<p>Following query collects all orders from the same day, as <code>{{dateFrom}}</code> would output <code>2017-10-13</code> and not eg. <code>2017-10-13 11:22:08</code></p>

<pre><code>{% set dateFrom = now|date_modify('-3600 seconds') %}
{% for order in craft.commerce.orders.dateOrdered( '&gt;= ' ~ dateFrom) %}
  ...
{% endfor %}
</code></pre>

<p>adding something like 
<code>craft.commerce.orders.dateOrdered( '&gt;= ' ~ dateFrom|date('c'))</code> would find any orders at all.</p>

<plugin-craftcommerce><datetime>
query orders by date AND time in craft commerce
# query orders by date AND time in craft commerce

(Asked by: username_0 on 2017-10-13)

How can I query all completed orders within the last hour? It seems craft is only comparing a date by YYYY-MM-DD.
Following query collects all orders from the same day, as {{dateFrom}} would output 2017-10-13 and not eg. 2017-10-13 11:22:08
{% set dateFrom = now|date_modify('-3600 seconds') %}
{% for order in craft.commerce.orders.dateOrdered( '>= ' ~ dateFrom) %}
  ...
{% endfor %}

adding something like 
craft.commerce.orders.dateOrdered( '>= ' ~ dateFrom|date('c')) would find any orders at all.

**Tags:** plugin-craftcommerce, datetime


---

## 1 answers

### Answer by username_1 on 2017-10-13. Score: 1 | Accepted answer

'>= ' ~ dateFrom|date('c')

is correct to output the DateTime object as a string with the time (and timezone) included. If you don’t use the filter it’s output in the Y-m-d format by default.
So my recommendation would be to double check what dateFrom|date('c') actually outputs and to compare it with the dateOrdered values in the CP or database.

> **Comments:**
> **username_0**: Thanks a lot, of course `'>= ' ~ dateFrom|date('c')` works perfectly fine.. I didn't get any output before, because (i think) the database time is UTC and  crafts dates are UTC+2. So I ended up taking the offset into account by doing this: `{% set dateFrom = now|date_modify( ((now|date("Z") + 3600)  * (-1)) ~' seconds') %}` and `.dateOrdered( '>= ' ~ dateFrom|date('c'))`  
> **username_1**: Something isn’t right, you should not need to factor in any timezone differences.  
> **username_0**: sry, for my late reply. there is indeed something odd going on between our DB and craft - but as this behavior only occurs on the dev-environment I am just going to ignore this for now. Anyways, the original question was answered perfectly! thx alot.  

---

