OK, I've put together some code which, in this particular case, finds the second (2nd) Sunday of every month depending on whether or not you're before or after it (specifically at 5:00PM that day).
<?php
$count = 0;
for( $i = 1 ; $i <=30 ; $i++ )//30 is much more than is needed
{
$date = date_create_from_format('Y-m-d H:i:s',date('Y-m-').$i.' 17:00:00');
if( $date->format('D') == 'Sun' )
{
$count++;
}
if( $count == 2 )
{
break;
}
}
$count = 0;
if( date('Y-m-d H:i:s') > $date->format('Y-m-d H:i:s') )
{
for( $i = 1 ; $i <=30 ; $i++ )
{
$date = date_create_from_format('Y-m-d H:i:s',date('Y-').(string)(((int)date('n')+1)%12).'-'.$i.' 17:00:00');
if( $date->format('D') == 'Sun' )
{
$count++;
}
if( $count == 2 )
{
break;
}
}
echo $date->format('F jS, Y');
}
else
{
echo $date->format('F jS, Y');
}
?>
So if you are at the green star it will display August 14, and if you're at the blue star it will display September 11:
My question is will this always be correct indefinitely?