Try something like this:
DB::table('texts')->whereRaw("strftime('%Y-%m', created_at) = '2010-1'")->get();
try to print out the resulted raw-Query of this code
DB::table('texts')->where(DB::raw("strftime('%Y-%m', created_at) = '2010-1'"))->get();
run it manually and see what's wrong
This may not be what you need, but, it is a discussion on Laracasts regarding dates, there are couple of good advises .
limp said:
Try something like this:
DB::table('texts')->whereRaw("strftime('%Y-%m', created_at) = '2010-1'")->get();
Thanks, this worked flawlessly. I wonder though, why it doesn't work with the embedded DB::raw() statement.
Here is very simple example, if you like : https://hdtuto.com/article/laravel-db-raw-where-clause-example
Hi
I think you have to try something like this:
DB::table('texts')->whereRaw("strftime('%Y-%m', created_at) = '2010-1'")->get();
Hope this helps you.
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community