0

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.

  • 2
    Get the first monday of the current month. If it's before now, get the first monday of the next month. – Barmar Jun 01 '23 at 17:52
  • Related content: [Get 1st day of next month](https://stackoverflow.com/q/13422032/2943403) and [How to find first day of the next month and remaining days till this date with PHP](https://stackoverflow.com/q/1777384/2943403) Adjusting the logic described in [Next Occurance of day and month](https://stackoverflow.com/q/54240080/2943403) is relevant. – mickmackusa Jun 01 '23 at 22:08

1 Answers1

0
$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