Filter records within a one-month interval

1

I have several items sold in a month and I would like to display only the items sold in the current month.

Example: In September I had a total of 30 items sold, and in August, 20 items.

How do I pick up the current date and check the quantity of items sold within a month?

I'm using Laravel.

    
asked by anonymous 04.09.2018 / 01:07

1 answer

1

You can do this:

Model::whereMonth('created_at', '12'); // apenas o mês 12 (Dezembro)
Model::whereYear('created_at', '2018'); // apenas o ano 2018
Model::whereDay('created_at', '2018-12-31'); // apenas o dia 

Remembering that you can combine these 3,

Model::whereMonth('created_at', '12')->whereYear('created_at', '2018');

I hope I have helped!

    
05.09.2018 / 14:23