I'd like to add get the x'th day of the y'th week in next month, i.e. the 4th monday of the next month (or arbitrary months away).
I can generate where I am at the moment with something like
$day = $date->dayOfWeek;
$week = $date->weekOfMonth;
But I am struggling to work out how to manipulate $date
to get where I want to. The alternative is to use PHP's relative formarts http://php.net/manual/en/datetime.formats.relative.php but I'd rather stick to Carbon if I can.
Another possiblity is to go to the first of the month with
$date->addMonth();
$date->day = 1;
and then do a loop to find the correct day and then add on weeks but this seems like a bit of a hack.
I ended up doing:
$day = $date->dayOfWeek();
$week = $date->weekOfMonth();
$date->addMonth();
$date->day = 1; //Move to first of the month
while($date->dayOfWeek != $day)
{
$date->addDay(); //Cycle through days until we get to correct day of the week
}
$date->addWeeks($week - 1);
Try this code
<?php
echo date('F jS, Y', strtotime('next Monday 2012-04-01'));
?>