Cakephp3 date_format error: Call to a member function format() on boolean FrozenTimeTrait.php

fnacimiento and ffallecimiento is date in the table

$personas = TableRegistry::get('Personas')->find();
$personas = $personas->select([
              'fnacimiento' => 'date_format(fnacimiento, "%d/%m/%Y")',
              'ffallecimiento' => 'date_format(ffallecimiento, "%d/%m/%Y")']);
$this->set('personas', $personas);

I want to move from 0000-00-00 to 00/00/0000 (YYYY-MM-DD to DD/MM/YYYY)

But it is not working it gives me this error:

Error: Call to a member function format() on boolean File …vendor/cakephp/chronos/src/Traits/FrozenTimeTrait.php Line: 161

The query is fine, because in mysql it works, but cakephp has some problem with the format, I do not understand it.

in .ctp
echo $persona->fnacimiento->format('d/m/Y');

or change the app config format
in config/bootstrap.php

Type::build(‘date’)->useLocaleParser()->setLocaleFormat(‘dd/MM/yyyy’);
Type::build(‘datetime’)->useLocaleParser()->setLocaleFormat(‘dd/MM/yyyy HH:mm’);
Type::build(‘timestamp’)->useLocaleParser()->setLocaleFormat(‘dd/MM/yyyy HH:mm’);

1 Like

Thank you!!

I tried to do:

$fncimiento->format('d/m/Y');

But I was wrong, when doing:

$fncimiento = $fncimiento->format('d/m/Y');

it worked without problems