Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel 5.4 get every day of the current week using Carbon

I've been using the syntax Carbon::now()->startOfWeek() and Carbon::now()->endOfWeek() for awhile now.

It returns the first day of the week which is the date of Monday and the last day of the week which is the date of Sunday. (I don't know why it wasn't Sunday and Saturday)

But now, I want to get every day of the current week. So what's left is the dates of Tuesday, Wednesday, Thursday, Friday, and Saturday.

Here's my exact syntax on getting Monday and Sunday.

$monday = Carbon::now()->startOfWeek();
$sunday = Carbon::now()->endOfWeek();
like image 969
Jan Ariel San Jose Avatar asked Jan 19 '26 17:01

Jan Ariel San Jose


1 Answers

You can progress through the week with addDay().

$monday = Carbon::now()->startOfWeek();
$tuesday = $monday->copy()->addDay();
$wednesday = $tuesday->copy()->addDay();

You can also check which day of the week you have.

$wednesday === Carbon::WEDNESDAY; // true
like image 195
Dwight Avatar answered Jan 22 '26 17:01

Dwight



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!