troubleshooting Question

Add months to date

Avatar of tonelm54
tonelm54 asked on
6 Comments1 Solution19 ViewsLast Modified:
I have a simple issue, where I need to add a number of months to a date, the input date format I cannot change, it will always be dd/mm/YYYY (eg 27/04/2021) as its coming from a html5 input control of date.

So, I generated my code which I thought would work according to several examples Ive found on the web:-
$inputDate = "27/04/2021";
$noMonths2Add = 3;
$effectiveDate = strtotime("+".$noMonths2Add." months",strtotime($inputDate));
echo json_encode(array("newDate"=>date('Y-m-d',$effectiveDate)));
And it spits out {"newDate":"1970-01-31"} - Which is NOT correct

Any ideas of what Ive done wrong?

Sorry, I could spend ages on this trying to figure out, but not had time to play with this, so probably a really simple issue :-(

Thank you in advance though
Join our community to see this answer!
Unlock 1 Answer and 6 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 6 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros