Answers.Body: <p>In Commerce 1, <code>craft.commerce.discounts</code> will return an array of Commerce_DiscountModel objects of all available discounts.</p>
  
  <pre><code>public function getAllDiscounts($criteria = [])
  {
      $records = Commerce_DiscountRecord::model()-&gt;findAll($criteria);
  
      return Commerce_DiscountModel::populateModels($records);
  }
  </code></pre>
  
  <p><code>Commerce_DiscountModel</code> objects have a <code>dateFrom</code> and a <code>dateTo</code> property, which is probably what you're looking for.</p>
  
  <p>Completely untested, but something like this:</p>
  
  <pre><code>{% set discount = null %}
  {% for d in craft.commerce.discounts %}
      {% if d.id == 1 %}
          {% set discount = d %}
          {% if discount.dateTo &gt; '2018-01-01 00:00:00' and discount.dateFrom &lt; '2018-12-31 23:59:59' %}
              Matches!
          {% endif %}
      {% endif %}
  {% endfor %}
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-08-31T22:33:54.217Z
Answers.LastActivityDate: 2018-08-31T22:33:54.217Z
Answers.UserDisplayName: Brad Bell
Body: <p>In Twig, I want to find out if a discount is valid based on start/end date.  startDate and endDate don't seem to exist and I can't inspect the discount object by using the json_encode filter (returns {}).</p>
  
  <p>How can we do this?</p>
  
  <p>This is the code used to grab the discount object:</p>
  
  <pre><code>{% set discount = null %}
  {% for d in craft.commerce.discounts %}
      {% if d.id == 1 %}{% set discount = d %}{% endif %}
  {% endfor %}
  </code></pre>
  
  <p>name, description and enabled variables are available but no startDate/endDate.</p>
  
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2018-08-30T00:16:46.020Z
Comments.Text: Can you share the code you're using to retrieve the discount model?
Comments.UserDisplayName: Brad Bell
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2018-08-30T05:21:06.570Z
Comments.Text: Sure it's in the description now.
Comments.UserDisplayName: biko
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2018-08-31T04:47:54.060Z
Comments.Text: @BradBell I forgot to mention you in my last comment but the code is now in the description.  Thanks in advance.
Comments.UserDisplayName: biko
Tags: <templating><plugin-craftcommerce><discounts>
Title: Commerce 1 find if Discount object is valid based on start/end dates (Twig)
ThreadText: # Commerce 1 find if Discount object is valid based on start/end dates (Twig)
  
  (Asked by: username_0 on 2018-08-29)
  
  In Twig, I want to find out if a discount is valid based on start/end date. startDate and endDate don't seem to exist and I can't inspect the discount object by using the json\_encode filter (returns {}).
  
  How can we do this?
  
  This is the code used to grab the discount object:
  
  ```
  {% set discount = null %}
  {% for d in craft.commerce.discounts %}
      {% if d.id == 1 %}{% set discount = d %}{% endif %}
  {% endfor %}
  
  ```
  
  name, description and enabled variables are available but no startDate/endDate.
  
  **Tags:** templating, plugin-craftcommerce, discounts
  
  > **Comments:**
  > **username_1**: Can you share the code you're using to retrieve the discount model?  
  > **username_0**: Sure it's in the description now.  
  > **username_0**: @username_1 I forgot to mention you in my last comment but the code is now in the description.  Thanks in advance.  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2018-08-31. Score: 1 | Accepted answer
  
  In Commerce 1, `craft.commerce.discounts` will return an array of Commerce\_DiscountModel objects of all available discounts.
  
  ```
  public function getAllDiscounts($criteria = [])
  {
      $records = Commerce_DiscountRecord::model()->findAll($criteria);
  
      return Commerce_DiscountModel::populateModels($records);
  }
  
  ```
  
  `Commerce_DiscountModel` objects have a `dateFrom` and a `dateTo` property, which is probably what you're looking for.
  
  Completely untested, but something like this:
  
  ```
  {% set discount = null %}
  {% for d in craft.commerce.discounts %}
      {% if d.id == 1 %}
          {% set discount = d %}
          {% if discount.dateTo > '2018-01-01 00:00:00' and discount.dateFrom < '2018-12-31 23:59:59' %}
              Matches!
          {% endif %}
      {% endif %}
  {% endfor %}
  
  ```
  
  
  ---
  
  