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();
Advertisement
Answer
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