Вторая суббота месяца Функция в PHP

Я нашел этот код PHP-кода для создателя и хочу реализовать его по-другому:

Цель состоит в том, чтобы код автоматически настраивал следующее утверждение как вторую субботу каждого месяца отныне до вечности:


Следующая встреча членов: Суббота, МЕСЯЦ, ДЕНЬ, ГОД , с 11:00 до полудня.

Как в: «Суббота, 12 февраля 2011 года , с 11:00 до полудня».


Я не PHP-гуру, может кто-то любезно отредактировать его для работы?

<?php function nextMeeting($nextMonth = false) { $day=date("j"); $month=date("n"); $year=date("Y"); if ($nextMonth) { $day=1; if ($month == 12) { $month=1; $year++; } else { $month++; } } $dayofweek=date("w"); $firstOfMonth=date("w",mktime(0, 0, 0, $month , 1, $year )); // figure out what date is the second Saturday of the month if ( $firstOfMonth > 0 ) { $firstSunday= 8 - $firstOfMonth; } else { $firstSunday= 1; } $firstSundayDate=date("D",mktime(0, 0, 0, $month , $firstSunday, $year)); // figure out what date the third monday of the month is if ( $firstOfMonth > 1) { $offSet = 8 - $firstOfMonth; } elseif ( $firstOfMonth == 0 ) { $offSet=1; } else { $offSet=0; } $thirdMonday= 15 + $offSet; $thirdMondayDate=date("D",mktime(0, 0, 0, $month , $thirdMonday, $year)); // lets see which of these dates now applies if ($day <= $firstSunday) { // we didn't miss the first meeting $nextMeeting=$firstSunday; $nextMeetingDate=mktime(0, 0, 0, $month , $nextMeeting, $year); } elseif ( ($day > $firstSunday) && ($day <= $thirdMonday) ) { // we missed the first meeting of the month, but can still make the second $nextMeeting=$thirdMonday; $nextMeetingDate=mktime(0, 0, 0, $month , $nextMeeting, $year); } else { // we need to wait until next month $nextMeetingDate=nextMeeting(1); $nextMeeting=nextMeeting(1); } return $nextMeetingDate; } $meeting=nextMeeting(); echo "Next membership meeting is on " . date('l dS \of F Y', $meeting); ?> 

Как насчет того, чтобы сохранить около 5000 строк и попробовать

 <? echo date('Ym-d', strtotime('second saturday of february 2011')); 

редактировать

Хорошо, я соврал в комментариях, я напишу это для вас.

 <? $now=date("U"); $monthyear=date("FY"); $secondsat=date('U', strtotime($monthyear.' second saturday')); if ($now>$secondsat) { $monthyear=date("FY", "next month"); $secondsat=date('U', strtotime($monthyear.' second saturday')); } echo date("m/d/Y",$secondsat); 

Вы можете немного изменить эту функцию:

 function nextMeeting($date = null) { $day = date("j", $date); $month = date("n", $date); $year = date("Y", $date); // remove the nextMonth bit $dayofweek=date("w", $date); $firstOfMonth=date("w",mktime(0, 0, 0, $month , 1, $year )); // all the same between here and the end return $nextMeetingDate; } for ($i = 0; $i < 12; $i++) { $date = mktime(0, 0, 0, date('m') + $i, date('d'), date('y')); echo "Next membership meeting is on " . date('l dS \of F Y', nextMeeting($date)); } 

Это должно дать вам следующие 12 встреч после сегодняшнего дня …

Мне нужно было найти диапазон дат DTS, так вот как я это сделал:

 $year = date("Y"); $dtsStart = date('Ymd 02:00:00', strtotime("Second Sunday Of March {$year}")); $dtsEnd = date('Ymd 02:00:00', strtotime("First Sunday Of November {$year}")); 

И, конечно же, вы можете заменить месяц простым кодированием.