rap-2-h
rap-2-h

Reputation: 32038

Set a date by weeknumber with carbon

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'));

Upvotes: 8

Views: 12226

Answers (1)

Daan
Daan

Reputation: 12246

I believe setISODate takes care of this:

$date = Carbon::now();
$date->setISODate(2017,3);
echo $date->startOfWeek();

Upvotes: 22

Related Questions