Can you show getMondayFromWeekNumber() method, and show the result of dd($monday);
Oct 28, 2021
6
Level 63
Problem to create a date with Carbon
Hello,
I have a problem with the first date which is never the $monday date. For the second date, I have no problem.
$year = $request->year;
$week = $request->week;
$monday = $this->getMondayFromWeekNumber($year, $week);
$fromDate = CarbonImmutable::createFromFormat('Y-m-d H:i:s', $monday.' 00:00:01');
$toDate = CarbonImmutable::createFromFormat('Y-m-d H:i:s', $monday.' 23:59:59')->addDays(6);
I'm looking around for 2 days without any solution.
Do you have any idea ?
Thanks a lot ;).
Vincent
Level 122
by the way, this is the same as your 'magic' method;
function getMondayFromWeekNumber($year, $week, $format = 'Y-m-d')
{
return (new Carbon())->setISODate($year, $week)->format($format);
}
Please or to participate in this conversation.