How do I upload an empty date?

I need to save a blank date, since in db that field can be null, when I create the form, that field is empty, because no value has been entered, but when sending the form it returns the error:

Call to a member function format() on array

How can I upload an empty date in Cakephp or ‘0000-00-00’ that also works for me?

I usually write a getter / setter or a helper to return null if needed:

    public static function fixInt($tonl)
        $tonl = (is_null($tonl) || empty($tonl) || strlen($tonl) < 1 ? NULL : $tonl);
        return $tonl;

does not work

In the db I save the date as “date” (year-month-day)

In the controller:

  if(empty($editPersona->ffallecimiento) || is_null($editPersona->ffallecimiento)) {              
              $editPersona->ffallecimiento = 0000-00-00;

In the view:

echo $this->Form->hidden('ffallecimiento', ['type' => 'date', 'value' => $editPersona->ffallecimiento 'class' => 'fechaFfallecimiento']);

Response header:


Captura de pantalla de 2020-04-12 13-44-20

$editPersona->ffallecimiento is empty and I want to upload it empty.

If your date is blank, do you want to store:

  • null


  • 0000-00-00

0000-00-00 is empty for a date, so you may need to store a null, if you don’t want anything to show.

If the field is not set to store a null, mysql will store 0000-00-00 anyway.

I prefer to save 0000-00-00 but even if I try to save:

$editPersona->ffallecimiento = null;

The error remains the same

ooohh the problem I do not have it with the date that I upload empty but with the date that I upload with content for some reason it tries to upload it as datetime instead of date