I wrote this piece of code in order to display the current date + 2 months :
<?php $date = date("d/m/Y"); $date = strtotime(date("d/m/Y", strtotime($date)) . "+2 months"); $date = date("d/m/Y",$date); echo $date; ?>
It does not seem to work as it displays : 01/03/1970.
What am I doing wrong?
Thanks for your help.
EDIT :
After reading comments and answers, I simplified and corrected it.
<?php $date = date("d/m/Y", strtotime(" +2 months")); echo $date; ?>
$effectiveDate = strtotime(date("Y-m-d", strtotime($effectiveDate)) . "+3 months");
The strtotime() function parses an English textual datetime into a Unix timestamp (the number of seconds since January 1 1970 00:00:00 GMT). Note: If the year is specified in a two-digit format, values between 0-69 are mapped to 2000-2069 and values between 70-100 are mapped to 1970-2000.
You're missing the second argument for the second strtotime()
call:
echo date('d/m/Y', strtotime('+2 months'));
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