Returning data from the database to twig, I dumped the array in twig and I see this
array (size=1)
'transactions' =>
array (size=150)
0 =>
array (size=12)
'id' => int 391
'trans_id' => string '294661627' (length=9)
'pay_amount' => string '40.00' (length=5)
'account_code' => string '874996' (length=6)
'pid' => int 726
'chrg_date' =>
object(DateTime)[825]
public 'date' => string '2019-11-19 00:00:00.000000' (length=26)
public 'timezone_type' => int 3
public 'timezone' => string 'America/New_York' (length=16)
'processed' => string 'EXACT' (length=5)
'process_date' =>
object(DateTime)[821]
public 'date' => string '2019-11-27 12:38:11.000000' (length=26)
public 'timezone_type' => int 3
public 'timezone' => string 'America/New_York' (length=16)
'encounter' => int 5287
'lname' => string 'Morris' (length=6)
'fname' => string 'Peter' (length=5)
'email' => string '' (length=0)
1 =>
I have two date objects in the array. So, in the template I use
<td>{{ transaction.chrg_date | date('Y-m-d') }}</td>
The data in the table is properly formated.
However, the dates are displayed like this:
Notice how all the dates are the same. I checked the database and this is not the data that is in the table.
What is the best way to access the date object in this array?
I found this post How to render a DateTime object in a Twig template.
None of the examples I have followed have worked.
As a final thought, I went back to my entity and looked at the getter method and it is this.
public function getChrgDate()
{
return $this->chrg_date;
}