I want to retrieve data of today from my database in Laravel.
I have already googling and applied several methods but not getting my answer.
PrescriptionTbl::whereDate('created_at', '=', $today)->get();
Where PrescriptionTbl
is the model and today
is current date like 2019-2-19
.But got NULL array.
To check the SQL I have used toSQL()
instead of get()
...and it shows below SQL in the browser
select * from `prescription_tbls` where date(`created_at`) = ?
I have also use Carbon
but also get a NULL array
PrescriptionTbl::whereDate('created_at', Carbon::today())->get();
How to solve it? Anybody Help Please?
You can use that;
PrescriptionTbl::whereDate('created_at', date('Y-m-d'))->get();
You can get it via new DateTime()
class
PrescriptionTbl::whereDate('created_at', '=', (new DateTime)->format('Y-m-d'))->get();
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