Answers.Body: <p><code>now</code> represents the current <code>DateTime</code> so unless you specify exactly the correct time in your field the condition <code>deliveryDate == now</code> will never become true. If the user visits the page one second earlier or one second later the condition will fail.</p>
  
  <p>For example: if your date is <code>2018-06-13 12:00:00</code> and <code>now</code> is <code>2018-06-13 12:00:01</code> both of your conditions will always fail. <code>now|date_modify("+ 1 day")</code> will result in <code>2018-06-14 12:00:01</code> and <code>12:00:00</code> is not <code>12:00:01</code></p>
  
  <p>you'll need to equalize the time or format it differently</p>
  
  <pre><code>{% if deliveryDate.modify('midnight') == tomorrow.modify('midnight') %}
  </code></pre>
  
  <p>or </p>
  
  <pre><code>{% if deliveryDate.format('Y.m.d') == tomorrow.format('Y.m.d') %}
  </code></pre>
  
  <p>You can read more about it in the <a href="http://php.net/manual/en/function.date.php" rel="nofollow noreferrer">docs</a></p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-06-13T14:13:07.087Z
Answers.Text: Understand @robin I just had no idea that a time parameter is included within `now` variable.
Answers.UserDisplayName: Dominik Krulak
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-06-13T13:59:12.183Z
Answers.LastActivityDate: 2018-06-13T13:59:12.183Z
Answers.UserDisplayName: Robin Schambach
Body: <p>The goal is to show a word when date field qualifies for <em>tomorrow</em> or <em>today</em> instead of numeric date.</p>
  
  <p>Setting and calling variables:</p>
  
  <pre><code>{% set deliveryDate = order.deliveryDate %}
  {% set tomorrow = now|date_modify("+ 1 day") %}
  
  {% if deliveryDate == tomorrow %}
    {% set deliveryDate = "tomorrow" %}
  {% elseif deliveryDate == now %}
    {% set deliveryDate = "today" %}
  {% else %}
    {% set deliveryDate = deliveryDate|date("d.m.Y") %}
  {% endif %}
  </code></pre>
  
  <p>My <em>date field</em> has selected value of tomorrow whereas the first statement should be truthy.</p>
  
  <p>So I think I'm comparing two objects with the same values but different classes?
  I had figured it out by formatting the date objects to strings using <a href="https://docs.craftcms.com/v2/templating/datetime.html#day" rel="nofollow noreferrer">day()</a> filter. </p>
  
  <p>But why is THAT happening on the first place? </p>
  
Tags: <datetime><globals>
Title: Comparing date field object with global variable "now" gives unexpected result
ThreadText: # Comparing date field object with global variable "now" gives unexpected result
  
  (Asked by: username_0 on 2018-06-13)
  
  The goal is to show a word when date field qualifies for *tomorrow* or *today* instead of numeric date.
  
  Setting and calling variables:
  
  ```
  {% set deliveryDate = order.deliveryDate %}
  {% set tomorrow = now|date_modify("+ 1 day") %}
  
  {% if deliveryDate == tomorrow %}
    {% set deliveryDate = "tomorrow" %}
  {% elseif deliveryDate == now %}
    {% set deliveryDate = "today" %}
  {% else %}
    {% set deliveryDate = deliveryDate|date("d.m.Y") %}
  {% endif %}
  
  ```
  
  My *date field* has selected value of tomorrow whereas the first statement should be truthy.
  
  So I think I'm comparing two objects with the same values but different classes?
  I had figured it out by formatting the date objects to strings using [day()](https://docs.craftcms.com/v2/templating/datetime.html#day) filter.
  
  But why is THAT happening on the first place?
  
  **Tags:** datetime, globals
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2018-06-13. Score: 2 | Accepted answer
  
  `now` represents the current `DateTime` so unless you specify exactly the correct time in your field the condition `deliveryDate == now` will never become true. If the user visits the page one second earlier or one second later the condition will fail.
  
  For example: if your date is `2018-06-13 12:00:00` and `now` is `2018-06-13 12:00:01` both of your conditions will always fail. `now|date_modify("+ 1 day")` will result in `2018-06-14 12:00:01` and `12:00:00` is not `12:00:01`
  
  you'll need to equalize the time or format it differently
  
  ```
  {% if deliveryDate.modify('midnight') == tomorrow.modify('midnight') %}
  
  ```
  
  or
  
  ```
  {% if deliveryDate.format('Y.m.d') == tomorrow.format('Y.m.d') %}
  
  ```
  
  You can read more about it in the [docs](http://php.net/manual/en/function.date.php)
  
  > **Comments:**
  > **username_0**: Understand @username_1 I just had no idea that a time parameter is included within `now` variable.  
  
  ---
  
  