Gorf Posted October 15, 2009 Share Posted October 15, 2009 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 More sharing options...
ialsoagree Posted October 16, 2009 Share Posted October 16, 2009 $strtotime = '11:59pm third Sunday '.date('F Y'); if (time() <= strtotime($strtotime)) { // before 3rd Sunday of the month } else { // after 3rd Sunday of the month } Link to comment https://forums.phpfreaks.com/topic/177846-stumped-by-third-day-of-month-problem/#findComment-937780 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.