<p>You can't access <code>date</code> this way, you'd need to use the <code>date</code> (<a href="https://craftcms.com/docs/3.x/dev/filters.html#date" rel="nofollow noreferrer">docs</a>) or <code>datetime</code> (<a href="https://craftcms.com/docs/3.x/dev/filters.html#datetime" rel="nofollow noreferrer">docs</a>) or even <code>atom</code> (<a href="https://craftcms.com/docs/3.x/dev/filters.html#atom" rel="nofollow noreferrer">docs</a>) filters.</p>
<p>In the case of your report, since you have multiple conditions, you would need to <a href="https://craftcms.com/docs/3.x/date-time-fields.html#querying-elements-with-date-fields" rel="nofollow noreferrer">pass those as an array</a> and use the <code>atom</code> filter.</p>
<p>Try:</p>
<pre><code>{% set purchases = purchases
    .postDate([
        'and', 
        '&gt;=' ~ settings.datetimeStartDate|atom, 
        '&lt;= ' ~ settings.datetimeEndDate|atom
    ]) %}
</code></pre>
<p>Alternatively, you can use <code>before()</code> (<a href="https://craftcms.com/docs/3.x/entries.html#before" rel="nofollow noreferrer">docs</a>) and <code>after()</code> (<a href="https://craftcms.com/docs/3.x/entries.html#after" rel="nofollow noreferrer">docs</a>) and pass date objects directly:</p>
<pre><code>{% set purchases = purchases
    .after(settings.datetimeStartDate)
    .before(settings.datetimeEndDate) %}
</code></pre>

CC BY-SA 4.0
2020-11-12T17:41:35.873Z
I was working off the Sprout Reports documentation, which had this format `settings.datetimeStartDate.date`. I will try it with the standard Craft code as you noted.
4midori
CC BY-SA 4.0
2020-11-12T17:57:02.983Z
Follow-up question, how would one output these values directly into a Sprout Report, that is, for testing? I can really only see if they work by outputting them either in the header row or a data row.
4midori
CC BY-SA 4.0
2020-11-13T12:32:48.547Z
Sorry but I'm not too sure. Do [the example templates](https://github.com/barrelstrength/craft-sprout-reports/blob/v1/src/examples/tutorialreport/results.twig) help?
Oli
CC BY-SA 4.0
2020-11-16T13:22:37.560Z
@4midori If you want to output these values outside of a Sprout Report, you'll just need to do so in a test template. To test within Sprout Reports you'll need to create a simple header and data row and run the report.
Ben Parizek
CC BY-SA 4.0
2020-11-17T16:16:31.103Z
@BenParizek, could you provide more explicit instructions on how to do that? I assume that values like _settings.whateverId_ are only set and retrieved within Sprout Report templates.
4midori
CC BY-SA 4.0
2020-11-20T02:27:46.627Z
@4midori as we're changing the topic here a bit, please drop us a note via support if this comment isn't enough. We do have some example templates in the repo. Check out the examples in the settings.twig and results.twig template here: https://github.com/barrelstrength/craft-sprout-reports/tree/v1.5.7/src/examples/tutorialreport
Ben Parizek
CC BY-SA 4.0
2020-11-12T12:28:38.943Z
2020-11-12T12:28:38.943Z
Oli
<p>Basic Sprout Report here, settings page:</p>
<pre><code>{{ forms.dateTimeField({
  label: &quot;Start Date&quot;|t,
  instructions: &quot;The start date of the date range you wish to display in your report.&quot;|t,
  id: 'datetimeStartDate',
  name: 'datetimeStartDate',
  value: settings.datetimeStartDate is defined ? settings.datetimeStartDate : now|date_modify(&quot;-30 days&quot;)
}) }}

{{ forms.dateTimeField({
  label: &quot;End Date&quot;|t,
  instructions: &quot;The end date of the date range you wish to display in your report.&quot;|t,
  id: 'datetimeEndDate',
  name: 'datetimeEndDate',
  value: (settings.datetimeEndDate is defined ? settings.datetimeEndDate : now)
}) }}
</code></pre>
<p>Results page:</p>
<pre><code>{% set purchases = craft.entries()
  .section('purchases')
  .limit(null)
%}

{% if settings.datetimeStartDate and settings.datetimeEndDate %}
  {% set purchases = purchases.postDate('and, &gt;= ' ~ settings.datetimeStartDate.date ~ ', &lt;= ' ~ settings.datetimeEndDate.date)
%}
{% endif %}
</code></pre>
<p>I am getting the following PHP error:</p>
<blockquote>
<p>PHP Notice – yii\base\ErrorException Undefined property:
DateTime::$date</p>
</blockquote>
<p>I have copied the datetime fields directly from the example docs, and tested the results template code with hardcoded dates, which works fine, but passing dates this way does not work.</p>

<php><error-message><plugin-sproutreports>
PHP error when trying to access dates in Sprout Reports
# PHP error when trying to access dates in Sprout Reports

(Asked by: username_0 on 2020-11-11)

Basic Sprout Report here, settings page:
{{ forms.dateTimeField({
  label: "Start Date"|t,
  instructions: "The start date of the date range you wish to display in your report."|t,
  id: 'datetimeStartDate',
  name: 'datetimeStartDate',
  value: settings.datetimeStartDate is defined ? settings.datetimeStartDate : now|date_modify("-30 days")
}) }}

{{ forms.dateTimeField({
  label: "End Date"|t,
  instructions: "The end date of the date range you wish to display in your report."|t,
  id: 'datetimeEndDate',
  name: 'datetimeEndDate',
  value: (settings.datetimeEndDate is defined ? settings.datetimeEndDate : now)
}) }}

Results page:
{% set purchases = craft.entries()
  .section('purchases')
  .limit(null)
%}

{% if settings.datetimeStartDate and settings.datetimeEndDate %}
  {% set purchases = purchases.postDate('and, >= ' ~ settings.datetimeStartDate.date ~ ', <= ' ~ settings.datetimeEndDate.date)
%}
{% endif %}

I am getting the following PHP error:

PHP Notice – yii\base\ErrorException Undefined property:
DateTime::$date

I have copied the datetime fields directly from the example docs, and tested the results template code with hardcoded dates, which works fine, but passing dates this way does not work.

**Tags:** php, error-message, plugin-sproutreports

---

## 1 answers

### Answer by username_1 on 2020-11-12. Score: 2 | Accepted answer

You can't access date this way, you'd need to use the date (docs) or datetime (docs) or even atom (docs) filters.
In the case of your report, since you have multiple conditions, you would need to pass those as an array and use the atom filter.
Try:
{% set purchases = purchases
    .postDate([
        'and', 
        '>=' ~ settings.datetimeStartDate|atom, 
        '<= ' ~ settings.datetimeEndDate|atom
    ]) %}

Alternatively, you can use before() (docs) and after() (docs) and pass date objects directly:
{% set purchases = purchases
    .after(settings.datetimeStartDate)
    .before(settings.datetimeEndDate) %}

> **Comments:**
> **username_0**: I was working off the Sprout Reports documentation, which had this format `settings.datetimeStartDate.date`. I will try it with the standard Craft code as you noted.  
> **username_0**: Follow-up question, how would one output these values directly into a Sprout Report, that is, for testing? I can really only see if they work by outputting them either in the header row or a data row.  
> **username_1**: Sorry but I'm not too sure. Do [the example templates](https://github.com/barrelstrength/craft-sprout-reports/blob/v1/src/examples/tutorialreport/results.twig) help?  
> **username_2**: @4midori If you want to output these values outside of a Sprout Report, you'll just need to do so in a test template. To test within Sprout Reports you'll need to create a simple header and data row and run the report.  
> **username_0**: @BenParizek, could you provide more explicit instructions on how to do that? I assume that values like _settings.whateverId_ are only set and retrieved within Sprout Report templates.  
> **username_2**: @4midori as we're changing the topic here a bit, please drop us a note via support if this comment isn't enough. We do have some example templates in the repo. Check out the examples in the settings.twig and results.twig template here: https://github.com/barrelstrength/craft-sprout-reports/tree/v1.5.7/src/examples/tutorialreport  

---

