strtotime or php alternative for "Next First Monday of the Month"

52 Views Asked by At

I am volunteering to create a website for a non-profit that has a meeting on the first Monday of every month. I was hoping to create PHP code that would return the date of the "Next First Monday of the Month".

<?php echo date("d-M-Y", strtotime("next first monday of the month"));?>

This works if the current date is AFTER the first Monday of the month, by showing next month's first Monday. But if the current date is BEFORE the first Monday of the month, it still shows next month's first Monday.

1

There are 1 best solutions below

0
Danny Van Der Sluijs On
$monday = new DateTime('first Monday of this month');

if ($monday < new DateTime()) {
    $monday new DateTime('first Monday of next month');
}
echo $monday->format('d-M-Y');

Making an additional check would resolve the issue