Call to a member function format () on boolean in
$fDevolucion = DateTime::createFromFormat('d-m-Y', $Fechadevolucion);
($prestamos = $objprestamo->addprestamo($fDevolucion->format('d-m-Y'),$cliente,$libro,$observacion)){ <-- ERROR EN ESTA LINEA
Call to a member function format () on boolean in
$fDevolucion = DateTime::createFromFormat('d-m-Y', $Fechadevolucion);
($prestamos = $objprestamo->addprestamo($fDevolucion->format('d-m-Y'),$cliente,$libro,$observacion)){ <-- ERROR EN ESTA LINEA
The error occurs because the variable $fDevolucion
is a boolean, punctually equal false
.
This can only happen when DateTime::createFromFormat
fails .
Validate that $Fechadevolucion
complies with the format d-m-Y
, that is, that $fDevolucion
is different from false
.
Example:
$fDevolucion = DateTime::createFromFormat('d-m-Y', $Fechadevolucion);
if ($fDevolucion !== false) {
$prestamos = $objprestamo->addprestamo($fDevolucion->format('d-m-Y'),$cliente,$libro,$observacion);
if ($prestamos) {
....
}
}
On your line 1 of code $fDevolucion = DateTime::createFromFormat('d-m-Y', $Fechadevolucion);
it is very likely that 'd-m-Y'
is not the correct format to process $Fechadevolucion
and at the end, $fDevolucion
is returning false
.
Try to do echo
to $Fechadevolucion
to make sure the correct format is 'd-m-Y'
.