Cakephp 4.0 Can't save date data

I tried to add new data for start date & end date. The data entered the array but somehow there’s error “Call to a member function format() on null” at index.php, line 33.

This is my SaleController Function Add:
public function add()
{
$sale = $this->Sales->newEmptyEntity();

        // pr($sale);die;
    // $data = $this->request->getData();
    // pr($data);exit;
    if ($this->request->is('post')) { 
        $data = $this->request->getData();
        // pr($data);exit;
        $date['start_date'] = !empty($data['start_date']) ? date('d-m-Y', strtotime($data['start_date'])) : '';
        $date['end_date'] = !empty($data['end_date']) ? date('d-m-Y', strtotime($data['end_date'])) : '';
        // $start_date = !empty($data['start_date']) ? date('Y-m-d', strtotime($sale->start_date->format('Y-m-d H:i:s')));
        // $end_date =  !empty($data['end_date']) ? date('Y-m-d', strtotime($sale->end_date->format('Y-m-d H:i:s')));
        $sale = $this->Sales->patchEntity($sale, $data); 
        if ($this->Sales->save($sale)) {
            $this->Flash->success(__('The sale has been saved.'));
     
            return $this->redirect(['action' => 'index']);
        }
        $this->Flash->error(__('The sale could not be saved. Please, try again.'));
    }
    $vehicles = $this->Sales->Vehicles->find('list', ['limit' => 200]);

    $users = $this->Sales->Users->find('list', ['limit' => 200]);
    $this->set(compact('sale', 'vehicles', 'users'));
}

Do all of your start_date and end_date records in the database have values, or are some of them null? If they can be null, then you need to account for that possibility in your templates, e.g. <?= $sale->start_date ? $sale->start_date->format('d M Y') : 'Unknown' ?>. If they are not supposed to be null but are being saved that way, then we’ll need to see how you create the form inputs for those fields. There are a couple of potential issues with your add function, but it seems to me that they should cancel each other out. I can explain more once you’ve shown your form creation.

i sent mutiple data including date, but only date save as null in database… already change the format date based on db but nothing works.

Well, as a wise man once said, “If they are not supposed to be null but are being saved that way, then we’ll need to see how you create the form inputs for those fields.”

It sounds like the problem is in the save process.

Possibly you need to look more closely at the data you’re putting in those date fields and whether they are passing validation.

Are you sure your edits are being saved as you seem to assume they are?

Are there any errors on the entity after the save call?

Is it possible something is allowing the entity to save but preventing those fields from being included? I believe the ‘accessible’ property on the entity might do that?

https://book.cakephp.org/4/en/orm/entities.html#mass-assignment