Use the following code to detect one week before and after easter.
// Create a DateTimeImmutable object with the current da
$easterDate = (new DateTimeImmutable())->setTimestamp(easter_date());
if (time() > $easterDate->modify('-1 week')->getTimestamp() && time() < $easterDate->modify('+1 week')->getTimestamp()) {
print 'easter';
}
else {
echo 'not easter';
}
The easter_date() function is key to calculating the date of easter here. If we call the function without passing any parameters then it returns easter for the current year.
Add new comment