How can I obtain a date in PHP that is both three months and three days ahead of the current system date?
$originalDate = date('m-d-Y'); // The original date
$monthsToSubtract = 3;
$newDate = date('m-d-Y', strtotime(-$monthsToSubtract, strtotime($originalDate)));
return $newDate;
The code provided is giving me an unexpected or unusual result.
Output =>> 01-01-1970
2
Answers
You can do it through DateTime PHP class, for reference you can visit the link https://www.php.net/manual/en/class.datetime.php
I would use the DateTime class as suggested by Kamran Allana. But I modified it to reflect more to the question.
Notice the string $newDate cannot be used to do calculations