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

AJAX form submit
I recently built a form that submits data to my database with an ajax function that is called throug

Database connection failure
Hello All,

I am trying to create new connection to Oracle DB 10.1,
I could not see a

How do i use vars in an array
Hiya peeps!

How do I use a var in an array. You will see $id but it isnt working.


Beginner question regarding Array's
Hi everyone, the page im working on has an array of variable at the top...

Code: $define_li

Java API in PHP?
I have an application that we use internally here at the office.

The software company provide

Search with relational database
Hey,

I have quite a complicated (for me anyway ) relational database for an apartments syste

Undefined variable: adHTML
Hello:

While checking my site error logs, I've noticed one repetitive error that fills the lo

line breaks in between fetched file names
Hi,

I have this code:
Code: <?php
if($dir = opendir('files')){
while (($f

Adding delete feature to my forum
Hello I am currently trying to add a delete feature to my forum. I believe I have everything built r

Pre-Fill out a PHP form...??
This is for work actually (geek squad). We have to fill out this online php form at work over and ov

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