I am working on a project in which I have to track all the records which are added in last hour of current time.
I am able to do this by using following query,
select count(*) as cnt
from log
where date >= DATE_SUB(NOW(),INTERVAL 1 HOUR);
but not able to do the same in Laravel.
You can use the Carbon date time api to get the last hour formated datetime
$count = \DB::table('logs')->where('date', '>=', \Carbon\Carbon::now()->subHour())->count();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With