I need to declare two dates in "Ymd"
format: $toDate
and $fromDate
.
$toDate
represents today's date and $fromDate
needs to be 4 months earlier than today.
$toDate = Date('Ymd'); $fromDate = ?
How do I create $fromDate
?
Use the magic of strtotime
:
$fromDate = date("Ymd", strtotime("-4 months"));
see the code below...
$fourmonthsback = date("Ymd", mktime(0, 0, 0, date("m")-4, date("d"), date("Y")));
OR
$fourmonthsback = mktime(0, 0, 0, date("m")-4, date("d"), date("Y"));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With