Help with if 3rd Monday of Month don't run script

I am new to PHP and have no idea how I want to modify this code to do as I wish. I have an event that we want displayed every single Monday between 7pm - 8pm. How ever the 3rd Monday of the month we do not want this to be displayed.

I realize that I can just hard code the dates I don’t want this displayed, but I would prefer if the code dynamically do this for me.

Any help would be appreciated.
Thanks,
William

[php]
$dayOfWeek = date(“N”);
$timeOfDay = date(“Gi”);

// Monday Event //
if (($dayOfWeek == 1 ) && ($timeOfDay >= 1900 && $timeOfDay <= 2000)){
echo ’


All information here


';

}[/php]

After an hour of searching and almost another testing… I came up with this solution…

First, it works on PHP5.3 and higher…

[php]

echo "Third Monday of this month is: " date(“Y-M-d”, strtotime("third monday " . date(“Y-m-t”, strtotime(“last month”))))

[/php]

For some reason, you have to select the last day of last month, then ask for the 3rd Monday.
Asking for the 3rd Monday of this month does not work. I see why you were frustrated…
So, that is how you get the 3rd Monday, now just alter your code to test if today is that day…

Hope that gets your there! Good luck…

ErnieAlex,

Thank you for your reply. As you mentioned I was quite frustrated. Normally I can do a search or look through the PHP manual, yet being new to PHP I could figure out if the formula even existed. I never did think to have it pull in the last day of the month in order to find the third Monday.

Thanks again,

  • William

Yep, I totally understand! I figured it would be a 30 second note to you. But, almost two hours later… LOL

Seems that silly function pulls differently due to the current date, your inputs and where it starts counting from.
( The third monday gives you 3 mondays from NOW! Yikes!)

So, finally it jumped in my mind about last-month which actually pulls the last day of last month.
(Found that out after 15 minutes of testing…) So, that is how I figured out the correct combo…

Glad I could help… CYA in the bitstream…

Sponsor our Newsletter | Privacy Policy | Terms of Service