0

I am looking for a PHP routine to look up our family reunion date each year so I wont have to keep manually looking it ip on a calender and entering it each year on the website.

The date is the sat before the 3rd Sunday in May.

I searched but found no answer on how to find the 3rd Sunday in a set month. I only found something on how to find the fist sun in the current month. Different question.

  • http://stackoverflow.com/questions/4880660/second-saturday-of-month-function-in-php – John Conde Apr 23 '13 at 20:25
  • What calendar or system are you using to put this information in here? Is it piggybacking off of joomla? droopal? something else? need more details. – ntgCleaner Apr 23 '13 at 20:26
  • In case you actually don’t want to program anything: http://utilitymill.com/utility/Nth_Weekday_in_Month – poke Apr 23 '13 at 20:30
  • I know you want to know in in PHP, but perhaps is suffice for you: How to create an `.ics` with this recurrence rule: http://webapps.stackexchange.com/q/6849 – Raul Pinto Apr 23 '13 at 20:33

3 Answers3

2

You can use strtotime() with a relative date format.

nullability
  • 10,545
  • 3
  • 45
  • 63
0

you can use a built in php strtotime

<?php
$s = 'Monday, September 28, 2009';
$time = strtotime($s);
$start = strtotime('last sunday, 12pm', $time);
$end = strtotime('next saturday, 11:59am', $time);
$format = 'l, F j, Y g:i A';
$start_day = date($format, $start);
$end_day = date($format, $end);
header('Content-Type: text/plain');
echo "Input: $s\nOutput: $start_day - $end_day";
?>

so in fact you can use 3 times "next sunday" while every time updating the $time to the new one

Dima
  • 8,586
  • 4
  • 28
  • 57
0

I think this should do it:

$time = strtotime('may 1 +3 sunday');

[Edit] Oops, forgot to go back a day:

$time = strtotime('may 1 +3 sunday -1 day');

[Edit2] Looped, for each year:

for ($year = 2013; $year <= 2020; $year++) {
    echo date('r', strtotime("may $year +3 sunday -1 day")), "\n";
}

Output:

Sat, 18 May 2013 00:00:00 -0400
Sat, 17 May 2014 00:00:00 -0400
Sat, 16 May 2015 00:00:00 -0400
Sat, 14 May 2016 00:00:00 -0400
Sat, 20 May 2017 00:00:00 -0400
Sat, 19 May 2018 00:00:00 -0400
Sat, 18 May 2019 00:00:00 -0400
Sat, 16 May 2020 00:00:00 -0400
Alex Howansky
  • 50,515
  • 8
  • 78
  • 98