Update the day of several recorded dates - CakePHP / Postgres


I am new using the CakePHP framework, in this opportunity I find the following problem: I need to modify the day of several dates registered in bd (postgresql).

I thought about extracting the day from the date that comes from the form and assembling the new date taking only the year and the month of the date already registered, all this with date_part(), something like this:

$ndate = $this->request->getData()['expired'];
$newDate =  "(date_part('year', expired) || '-' || date_part('month', expired) || '-' || date_part('day', '$ndate'::date))::date";

$fields += array('expired' => $newDate);

if ($this->Payments->updateAll($fields,$options)){
    $a = true;
    $rFlash ='Successfully updated payments';

I tried the resulting full query in pgAdmin and it works fine … the problem (at least that’s what I think ;-P) is with cakePHP, which gives me the following error message:

Database Error

Error: SQLSTATE[22007]: Invalid datetime format: 7 ERROR: invalid input syntax for type date: "(date_part("year", expired) || - || date_part("month", expired) || - || date_part("day", 2018-08-05::datetime))::datetime"

I thank you in advance for all the help you can give me.