W
W
Way2018-09-23 21:19:34
Laravel
Way, 2018-09-23 21:19:34

How to get weekly data?

There is data in this style, 5ba7d9288cd1b045712023.pngI need to get data for the current week and a week before the current one. If today is Wednesday, then you need data from Monday to today. I found data about the current week that can be obtained through Carbon

Carbon::setWeekStartsAt(Carbon::MONDAY);
Carbon::setWeekEndsAt(Carbon::SUNDAY);
$startOfWeek = $sales->whereBetween('created_at', [Carbon::now()->startOfWeek(), Carbon::now()->endOfWeek()])->get();

The main question is how can I get data a week before the current one? From Monday to Sunday.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Antonio Solo, 2018-09-23
@wayheming

subtract 7 days from current date ?

$startOfWeek = $sales->whereBetween('created_at', [
Carbon::now()->subDays(7)->startOfWeek(), 
Carbon::now()->subDays(7)->endOfWeek()
])->get();

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question