Support the ongoing development of Laravel.io →
Database Eloquent
Last updated 2 years ago.
0
Solution

Try something like this:

DB::table('texts')->whereRaw("strftime('%Y-%m', created_at) = '2010-1'")->get();
Last updated 2 years ago.
0

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

Last updated 2 years ago.
0

This may not be what you need, but, it is a discussion on Laracasts regarding dates, there are couple of good advises .

Last updated 2 years ago.
0

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.

Last updated 2 years ago.
0

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.

0

Sign in to participate in this thread!

Eventy

Your banner here too?

eFrane efrane Joined 20 Feb 2014

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.