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'));
Carbon also allows us to generate dates and times based on a set of parameters. For example, to create a new Carbon instance for a specific date use the Carbon::createFromDate() method, passing in the year, month, day, and timezone, as in the following example. <? php require __DIR__ .
You can use array_map to produce this kind of result: $dates_formatted = array_map(function($entry) { // transform the Carbon object to something like 'Dec 25, 1975' return $entry['date']->toFormattedDateString(); }, $dates);
An API extension for DateTime that supports 281 different languages.
I believe setISODate
takes care of this:
$date = Carbon::now();
$date->setISODate(2017,3);
echo $date->startOfWeek();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With