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)

Did you know?Explore Trending and Topic pages for more stories like this.
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

Show specific day of the week
I have been racking my brain trying to get this function to work properly and it is doing so for eve

Error querying database.
I get the above error when trying to insert some values to a datatable.
Here's the code :

highlighting search terms
well, I started this in the regular PHP section, but it no longer fits there. Suffice it to say, I'm

SESSION CHECK WORKS "MOST" of the time... whats going on?
i have a sign in check thats included in every page that is a members only page which is basically a

mail with attachment problems
Hi. I have the following code:
Code: else if(file_exists("site".$timp.".zip")

Typing math
I've added support for typesetting math using LaTeX on the forums.

Example:
Code: [Select]

Not showing whole name with mail () script
I sent up a simple mail form with the PHP mail() script. One problem is when it sends an email with

file downloaded can't be read !!
<?php
$fileName = 'mypic.jpg';
$mimeType = 'image/jpeg';
header('content-dispositio

Getting rid of quotes when printing data
Hi Guys, I use the filter_var FILTER_SANITIZE_STRING to filter the textarea input. The function esca

newbie question
Hi out thereIm totaly new in this forum and to .net and vb so here is a totaly newbie question.I wan

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