Jump to content

Stumped by Third Day of Month problem


Gorf

Recommended Posts

I am trying to build an algorithm that will essentially do this:

$this_month = October
$third_sunday = CalculateThirdSunday(October)

if ( ( TodaysDate before $third_sunday ) | ( TodaysDate == $third_sunday )
  do something
else CalculateThirdSunday(November)
  do something else

 

So the sorta pseudo-code above should reveal that I want a function that will always take the current month and calculate the third Sunday.  Then if it's on or before that third sunday do something.  However if it is after the the third Sunday, then we will calculate the third sunday of next month and then do something.

 

I can calculate what the third sunday out from now() is quite trivially:

 

<?PHP echo date('l jS F (Y-m-d)', strtotime('third Sunday')); ?>

 

But anyone got any idea how to find the third sunday from the beginning of the month?  I tried something like

 

<?PHP echo date('l jS F (Y-m-d)', strtotime('2009-10-01 +third Sunday')); ?>

 

but that appears to not work.  It tells me the next sunday is in Feb.  LOL

 

 

Link to comment
https://forums.phpfreaks.com/topic/177846-stumped-by-third-day-of-month-problem/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.