Johnny
Johnny

Reputation: 111

PHP Convert separate day,month and year to date

I looked in many threads regarding this issue but still can't get to the bottom of this one. Here is my code:

$birthdate_ts = strtotime("$year-$num_month-$day");
$birthdate = date("d/m/Y",$birthdate_ts);

Where $day $num_month and $year are numbers (example 1 10 1990). The result I'm getting is 1/1/1970 every time. I also tried different variations for the "strtotime()" input and still nothing. Where am I wrong?

Upvotes: 1

Views: 3416

Answers (1)

mikeb
mikeb

Reputation: 11267

Your parse format is "d/m/y" and your format you are creating is "Y-m-d". They need to match. Try this:

$birthdate_ts=strtotime("$year-$num_month-$day");
$birthdate=date("Y-m-d",$birthdate_ts);

Upvotes: 3

Related Questions