'How to subtract 1 week from Easter Date in php

I have been trying to get php to subtract 1 week from Easter and the outputs are just downright bizarre.

This is what I currently have

<?php
    $year = date("Y");
    $easterdate = date('d-m-y',easter_date($year));
    $newdate = strtotime('-7 days', strtotime($easterdate)); 
?>
<body>
<?php echo $newdate;?> <br>
<?php echo $easterdate;?> <br>
</body>

The output I get is

newdate = 14-04-04 easterdate = 04-04-21

For some reason (which maybe very obvious that I can't see) is that when I try to calculate the minus 7 days, it subtracts the years and reformats it to Y-M-D.

I have reviewed the other forum questions about subtracting time and have tried various methods including the php.net site.

php


Solution 1:[1]

Thanks everyone for your help and pointing out my errors.

I don't know what happened, but it may have been a browser refresh problem.

My final code which works is

<?php
$year = date("Y");
$easterdate = date('d-m-y',easter_date($year));
$newdate = strtotime('-7 days', easter_date($year)); 
$newdate = date('d-m-y',$newdate);
?>
<body>
<?php echo $newdate;?> <br>
<?php echo $easterdate;?> <br>

The outputs are

newdate = 28-03-21

easterdate = 04-04-21

Solution 2:[2]

Palm Sunday

$PalmSunday = strtotime('-1 week', easter_date());
echo date('M-d-y',$PalmSunday);

Beginning of Scrutinies

$FirstScrutiny = strtotime('-4 week', easter_date());
echo date('M-d-y',$FirstScrutiny);

Solution 3:[3]

Try this one if i catch your problem,

echo date("d-m-y", strtotime(date("Y-m-d")." -7 days"));

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Andrew H
Solution 2
Solution 3 Md. Lalchand