1
Good afternoon!
I made a function to calculate the difference of days between two dates, one of these dates is the current one (I create using the new DateTime()) and the other picks up in the database and is saved as datetime
foreach ($eventos as $e) {
$qtdDias = $this->calculaDiferenca($e->dataEv);
if ($qtdDias > 0 && $qtdDias <= 7) {
array_push($evs,$e->id);
}
}
function calculaDiferenca($DataEvento){
$hoje = new DateTime();
$diferenca = $hoje->diff($DataEvento);
return $diferenca->d;
}
How I create the spine:
$table->datetime('dataEv')->nullable();
When I run the error on the line where I calculate the difference:
Datetime::diff() expects Parameter 1 to be Datetimeinterface, string Given
The return of
dd($e->dataEv)have what as a result? See the error message, is returning a string, not aDateTime– gmsantos
I know, that’s the problem. I need to convert this string into a Datetime
– Marcio
What is the format/content of this returned string ?
– Edilson