Stumped by Third Day of Month problem


Posted on 16th Feb 2014 07:03 pm by admin

I am trying to build an algorithm that will essentially do this:
Code: [Select]$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

No comments posted yet

Your Answer:

Login to answer
175 Like 11 Dislike
Previous forums Next forums
Other forums

Form a inline view based on the results of the previous query?
Hi Experts,
Can we form a inline view on the results of a previous query (another inline view)?

Simple Scraper... Weird Output
Okay, maybe I just need a Blue Monster and some sleep, but....

I'm scraping a ringtone site

serializing objects - loses methods - the point being?
Hi

I know that serializing an object will lose the methods. But whats the point in that? What

How can I uploading Transactional Data from Legacy to New SAP system
Hell Gurus,

I am overwhelmed with questions on how to migrate huge volume of Sales Orders

Mail form doesn't send Russian/Cyrillic characters correctly?
When someone enters foreign characters (like Cyrillic text, and Japanese/Chinese probably gives the

Saving data from a form into a file
Hey everybody,

Sorry, I am really new to PHP coding and such but a project kind of got thrust

Ajax Issues - Update Panel / Timer. Intellisense doesn't know about them
Type 'System.Web.UI.ScriptManager' does not have a public property named 'UpdatePanel'. That is wha

Registration
ok so i have a site where people can register and login which works now thanks to someone on here th

Optimize Code
Just started getting into the use of cookies. The following code will redirect users to a set URL s

Formatting echo from database
So I have a database that stores First and last names, then echos them back to a website, as of now

Sign up to write
Sign up now if you have flare of writing..
Login   |   Register
Follow Us
Indyaspeak @ Facebook Indyaspeak @ Twitter Indyaspeak @ Pinterest RSS



Play Free Quiz and Win Cash