The FIRST FRIDAY of each month, lets say a meeting is held.
This group has online registration for this meeting. The WEDNESDAY & THURSDAY prior to the first Friday, registration for the meeting must be closed. After those wed and thurs, they would like to accept registration again (yes, beginning the first friday).
But, what if The wednesday before the first Friday is still the previous month? What if the Wednesday AND Thursday before the first Friday are in the previous month?
Hopefully that's understandable?
My first attempt was:
Code: Select all
<?php
$firstwed = strtotime("first Wednesday, first Thursday". date("F Y"));
$now = strtotime('today');
if( $firstwed == $now) {
echo "Registration is closed until our next event!";
// do something
} else {
echo 'REGISTER AND PAY ONLINE HERE';
// do something else
}
?>Code: Select all
// get date object for today
$today = new DateTime();
// get the date object for the first friday of the current month
$ffstr = 'First Friday of ' . date('F') .' '. date('Y');
$first_friday = new DateTime($ffstr);
// create a cutoff date object two days before the first friday
$cutoff_date = clone $first_friday;
$cutoff_date->sub(new DateInterval('P2D'));
// compare today's date to the cutoff date/first friday date
if ($today < $cutoff_date || $today > $first_friday) {
echo 'REGISTER AND PAY ONLINE HERE';
} else {
echo "Registration is closed until our next event!";
} So they came up with this:
Code: Select all
ff = strtotime('first friday ' . date('F Y'));
$twoDaysPast = strtotime('-2 day', $ff);
$oneDaysPast = strtotime('-1 day', $ff);