Try date('n') instead - without leading zero.
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...
This will do the job
$orders_this_month = Order::where( DB::raw('MONTH(created_at)'), '=', date('n') )->get();
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.
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();
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community