This functions is based on Carbon date plugin that recieves 2 arguments. First argument is year and second argument is week number of the year. An array is returned based on parameters that includes start and end date.
Function
function getStartAndEndDateOfWeek($year, $week) { $date = Carbon::now(); $date->setISODate($year, $week); $date->setWeekStartsAt(Carbon::MONDAY); $date->setWeekEndsAt(Carbon::SUNDAY); return (object) [ 'start_date' => $date->copy()->startOfWeek(), 'end_date' => $date->copy()->endOfWeek() ]; }
Calling The Function
$dates = getStartAndEndDateOfWeek(2021, 25); echo $dates->start_date->format('d/m/Y'); echo $dates->end_date->format('d/m/Y');
Output
21/06/2021 27/06/2021
Leave A comment
Email address is optional and will not be published. Only add email address if you want a reply from blog author.
Please fill required fields marked with *