I m trying to create an object in Laravel, when i set the date I get an error. Thats my code:
$result = pg_query($this->conn, "SELECT * FROM cliente");
if (!$result) {
$this->message('Error to query cliente');
exit;
}
while ($row = pg_fetch_row($result)) {
if($row[7]== null){
$cliente->fecha_nacimiento = null;
}
else{
$fechaString = (string)$row[7];
//$this->info($fechaString);
$fecha = DateTime::createFromFormat('Y-m-d', trim($fechaString));
$cliente->fecha_nacimiento = $fecha;
}
}
The error is:
[ErrorException]
DateTime::createFromFormat() expects parameter 2 to be string, object given
If I use Carbon:
$fecha = Carbon::createFromFormat('Y-m-d', trim($fechaString));
Getting:
[InvalidArgumentException]
The separation symbol could not be found
Unexpected data found.
Trailing data
Thanks in advance!
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire