Error 'Call to a member function format'

0
  

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 
    
asked by ALEX 08.04.2017 в 19:24
source

2 answers

1

The error occurs because the variable $fDevolucion is a boolean, punctually equal false . This can only happen when DateTime::createFromFormat fails .

Solution:

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) {
     ....
  }
}
    
answered by 08.04.2017 в 20:14
0

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' .

    
answered by 08.04.2017 в 20:17