In my Laravel project I have to be calculating the members commission in each week of a year. Please how do I get the start datetime and end datetime of all the weeks in each year? database used is mysql.
In my Laravel project I have to be calculating the members commission in each week of a year. Please how do I get the start datetime and end datetime of all the weeks in each year? database used is mysql.
setIsoDate() sets a carbon date, by year and week. When you got that, you can use startOfWeek() and endOfWeek() to get the beginning and end of them.
$year = 2022;
foreach (range(1, 53) as $week) {
$date = Carbon::now();
$date->setISODate($year, $week);
$date->copy()->startOfWeek()
$date->copy()->endOfWeek();
}