Voglio restituire tutte le righe nella tabella del mio database che sono un giorno o meno vecchie. Sto usando Laravel 4. Questo è quello che ho provato:Laravel/Eloquent e confronto date
$date = date('Y-m-d H:i:s');
return MainContact::where(DATEDIFF('timestamp', $date), '<=', 1)->get();
Questo non funziona. Ho letto la documentazione e non sembra che tu possa passare le funzioni di MySavel MySQL. timestamp
è un campo datetime. Come posso confrontare queste date in Laravel 4?
Sì, ho dovuto aggiustare il suo MySQL. – sehummel
Ho fatto 'MainContact :: where ('timestamp', '>', DB :: raw ('NOW() - INTERVAL'. $ Interval. 'DAY') -> get();' e poi passato nell'intervallo – sehummel
Puoi anche usare 'strtotime (" - 1 giorno ")', come questo: 'MainContact :: where ('timestamp', '>' strtotime (" - {$ interval} day ")) -> get(); ' –