Date conversion fails

I am having trouble returning my code for the correct answer.

$Birthd = '06-27-1996';

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

      

When I run this answer, "12-31-1969"

I believe this is the default sort, but what can I do to restore the code? If it is started with a different line $Birthd

such as"07-03-1996".

+3


source to share


2 answers


You need to change the date format of the string 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

Ref: - php various acceptable date formats

0


source


Change - to / and try ...



$Birthd = '06/27/1996';

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

      

0


source







All Articles