3

I am having issues getting my code to return the correct response.

$Birthd = '06-27-1996';

$NewISSdate = date("m-d-Y", strtotime(date("m-d-Y", strtotime($Birthd)) . " +21 years"));

When I run this the response is: "12-31-1969"

I believe this is a default date of sorts, but what can I do to repair my code? If ran with a different $Birthd string such as "07-03-1996".

Alive to die - Anant
  • 70,531
  • 10
  • 51
  • 98

2 Answers2

0

Change - to / and try...

$Birthd = '06/27/1996';

$NewISSdate = date("m/d/Y", strtotime(date("m/d/Y", strtotime($Birthd)) . " +21 years"));
Arshad Shaikh
  • 564
  • 1
  • 3
  • 13
0

You need to change string date format and then add years to it like below:-

$Birthd = '06-27-1996';
$Birthd = str_replace("-","/",$Birthd);

echo $NewISSdate = date("Y-m-d", strtotime(date("Y-m-d", strtotime($Birthd)) . " + 21 years"));

Output:-https://eval.in/835509 OR https://eval.in/835555

Reference:- php different acceptable date formats

Alive to die - Anant
  • 70,531
  • 10
  • 51
  • 98