Set a date by weeknumber with carbon
Asked Answered
G

1

8

I know I can get the week number with Carbon by calling $my_date->weekOfYear. Is there a way to set a date by week number?

I mean is there something for initializing a date to the first day of the 3rd week of 2017 year?

I can initialize a date to the start of the year, I think it's a good start but I don't know what to do next:

$a = (new \Carbon\Carbon('2017-01-01'));
Gil answered 16/10, 2017 at 13:56 Comment(0)
J
22

I believe setISODate takes care of this:

$date = Carbon::now();
$date->setISODate(2017,3);
echo $date->startOfWeek();
Jamey answered 16/10, 2017 at 13:58 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.