Filter records within one month interval

Asked

Viewed 100 times

1

I have several items sold in a month and 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 take the current date and check the amount of items sold within one month?

I’m wearing Laravel.

1 answer

1

you can do so:

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’ve helped!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.