<p>I attempted to get senate directly and output one element of it but no matter what index/key I set it would give me an error. Also, trying to change the object (or whatever it happened to be) in the PHP caused errors as well. I needed up just doing |first and |date to grab the date I needed and format it. The timezone_type and timezone were being converted into dates (December 1969 and current date) for some reason.</p>

<pre><code>{% set batchRowStats = craft.analytics.loadSavedBatch() %}
{% for stat in batchRowStats %}
    {{ stat['senddate']|first|date("F j, Y") }}
{% endfor %}
</code></pre>

<p>I did change on thing in the PHP. I added (array) before the object inside of the array it's in. There are more complications to this scenario but I was assigning it to another variable and adding it to a different array. No matter what way I tried to extract the variable it would give me errors. String conversion gave me array error and array conversion usually gave me a string error and several others along the way. After placing (array) in front of it while assigning it to a variable it seemed to behave a bit better.</p>

<pre><code>$emptyDateArray = (array) $innerResults['BatchStartDate'];
</code></pre>

CC BY-SA 3.0
2017-06-21T00:48:47.997Z
2017-06-21T00:48:47.997Z
Cyberio
<p>I'm trying to display a saved date from a json file.
I currently have:</p>

<pre><code>{% set batchRowStats = craft.analytics.loadSavedBatch() %}

{% for stat in batchRowStats %}
    &lt;tr&gt;
        &lt;td&gt;{{ stat['senddate'].date }}&lt;/td&gt;
    &lt;/tr&gt;
{% endfor %}
</code></pre>

<p>And the information in the JSON file is:</p>

<pre><code>[{"batchid":368,"total":1111,"opened":0,"clicked":0,"optout":0,"bounced":0,"subject":"subject line","senddate":{"date":"2017-06-02 06:00:22.000000","timezone_type":3,"timezone":"UTC"}}
</code></pre>

<p>I am getting this error:</p>

<p>Impossible to access an attribute ("date") on a string variable ("").</p>

<p>Which I am assuming it's because this information may be in a DateTime or object of sorts. I really need to just display "June 2, 2017" with a date_format but I'm not even sure how to get the string to display.</p>

CC BY-SA 3.0
2017-06-20T17:24:11.617Z
If you `{{ dump(stat['senddate']) }}`, what does it output?
Brad Bell
CC BY-SA 3.0
2017-06-20T17:25:22.527Z
array(3) {
  ["date"]=>
  string(26) "2017-06-02 06:00:22.000000"
  ["timezone_type"]=>
  int(3)
  ["timezone"]=>
  string(3) "UTC"
}
Cyberio
CC BY-SA 3.0
2017-06-20T17:27:10.233Z
I was able to
                                     {% for datestat in stat['senddate'] %}
                                      <td>{{ datestat|date('M j, Y') }}</td>
                                     {% endfor %}
and it outputs three dates.: Jun 2, 2017   Dec 31, 1969   Jun 20, 2017
Cyberio
CC BY-SA 3.0
2017-06-20T17:45:40.783Z
Seems like that sorts your issue, then? Would you mind adding that as an official answer?
Brad Bell
CC BY-SA 3.0
2017-06-20T17:49:27.607Z
Well, it sort of fixes it because I do get a date but why is it outputting three and how do I only get one? I tried .limit(1) and .first() but it gives me errors. Should I try something besides a for loop? If so, what?
Cyberio
CC BY-SA 3.0
2017-06-20T18:26:02.080Z
I'm reworking the data on file write to remove the extra array elements. Twig is interpreting the timezone and timezone type date elements as dates (Dec 1969 and current date). Can't find a way to grab the first element so it's probably better practice to only write the data I need.
Cyberio
CC BY-SA 3.0
2017-06-21T00:28:34.987Z
Hard to tell without your updated code, but you should just be able to grab the `senddate` directly?  i.e. `{% set datestat = stat['senddate'] %} {{ datestat|date('M j, Y') }}`
Brad Bell
CC BY-SA 3.0
2017-06-21T00:29:05.650Z
Regardless, be sure and add an official answer if you get it sorted. :)
Brad Bell
<datetime><php>
Displaying variable in array in array = Impossible to access an attribute ("date") on a string variable ("")
# Displaying variable in array in array = Impossible to access an attribute ("date") on a string variable ("")

(Asked by: username_0 on 2017-06-20)

I'm trying to display a saved date from a json file.
I currently have:
{% set batchRowStats = craft.analytics.loadSavedBatch() %}

{% for stat in batchRowStats %}
    
        {{ stat['senddate'].date }}
    
{% endfor %}

And the information in the JSON file is:
[{"batchid":368,"total":1111,"opened":0,"clicked":0,"optout":0,"bounced":0,"subject":"subject line","senddate":{"date":"2017-06-02 06:00:22.000000","timezone_type":3,"timezone":"UTC"}}

I am getting this error:
Impossible to access an attribute ("date") on a string variable ("").
Which I am assuming it's because this information may be in a DateTime or object of sorts. I really need to just display "June 2, 2017" with a date_format but I'm not even sure how to get the string to display.

**Tags:** datetime, php

> **Comments:**
> **username_1**: If you `{{ dump(stat['senddate']) }}`, what does it output?  
> **username_0**: array(3) {   ["date"]=>   string(26) "2017-06-02 06:00:22.000000"   ["timezone_type"]=>   int(3)   ["timezone"]=>   string(3) "UTC" }  
> **username_0**: I was able to                                      {% for datestat in stat['senddate'] %}                                       <td>{{ datestat|date('M j, Y') }}</td>                                      {% endfor %} and it outputs three dates.: Jun 2, 2017   Dec 31, 1969   Jun 20, 2017  
> **username_1**: Seems like that sorts your issue, then? Would you mind adding that as an official answer?  
> **username_0**: Well, it sort of fixes it because I do get a date but why is it outputting three and how do I only get one? I tried .limit(1) and .first() but it gives me errors. Should I try something besides a for loop? If so, what?  
> **username_0**: I'm reworking the data on file write to remove the extra array elements. Twig is interpreting the timezone and timezone type date elements as dates (Dec 1969 and current date). Can't find a way to grab the first element so it's probably better practice to only write the data I need.  
> **username_1**: Hard to tell without your updated code, but you should just be able to grab the `senddate` directly?  i.e. `{% set datestat = stat['senddate'] %} {{ datestat|date('M j, Y') }}`  
> **username_1**: Regardless, be sure and add an official answer if you get it sorted. :)  

---

## 1 answers

### Answer by username_0 on 2017-06-21. Score: 1 | Accepted answer

I attempted to get senate directly and output one element of it but no matter what index/key I set it would give me an error. Also, trying to change the object (or whatever it happened to be) in the PHP caused errors as well. I needed up just doing |first and |date to grab the date I needed and format it. The timezone_type and timezone were being converted into dates (December 1969 and current date) for some reason.
{% set batchRowStats = craft.analytics.loadSavedBatch() %}
{% for stat in batchRowStats %}
    {{ stat['senddate']|first|date("F j, Y") }}
{% endfor %}

I did change on thing in the PHP. I added (array) before the object inside of the array it's in. There are more complications to this scenario but I was assigning it to another variable and adding it to a different array. No matter what way I tried to extract the variable it would give me errors. String conversion gave me array error and array conversion usually gave me a string error and several others along the way. After placing (array) in front of it while assigning it to a variable it seemed to behave a bit better.
$emptyDateArray = (array) $innerResults['BatchStartDate'];


---

