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

Try date('n') instead - without leading zero.

Last updated 2 years ago.
0

Thanks jarektkaczyk,

Still no joy, my record created_at is "created_at":"2014-04-02 12:22:17" and with:

$orders_this_month = Order::where( DB::raw('MONTH(created_at)', '=', date('n') ))->get();

I get no result...

Last updated 2 years ago.
0

This will do the job

$orders_this_month = Order::where( DB::raw('MONTH(created_at)'), '=', date('n') )->get();
Last updated 2 years ago.
0

Perfect - man I should have spotted that!

Last updated 2 years ago.
0

I will have to do the same thing now, but I just realized that after a year, this will return the same month for both years in a row. That said, I think the best option is to user Year-Month.

Last updated 2 years ago.
0

You could always use carbon.

To select within the current month

Order::where('created_at', '>=', Carbon::now()->startOfMonth())->get();

To select within the last month

Order::where('created_at', '>=', Carbon::now()->subMonth())->get();
Last updated 2 years ago.
0

Thanks @iWader! Worked great :)

0

Sign in to participate in this thread!

Eventy

Your banner here too?

netm netm Joined 2 Apr 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.