Good afternoon!
I made a function to calculate the difference of days between two dates, one of these dates is the current one (which I create using new DateTime()
) and the other one gets 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 do I create the column:
$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