din din - 29 days ago 9
PHP Question

How to convert date into correct format?

I'm using following code to convert user selected date into following date format for saving purpose. But it doesn't convert 2017 year. It get it as 2016.

$pieces = explode(" ", $start);
$new_date_in = date("Y-m-d",strtotime($pieces[2]." ".$pieces[1]." ".$pieces[0]));


when I echo $start , it gives Wed Mar 08 2017

but when I echo $new_date_in, it gives 2016-03-09

2016 dates convert it correctly. please give me a solution.

Answer
$pieces = explode(" ", $start);
$new_date_in = date("Y-m-d",strtotime($pieces[2]." ".$pieces[1]." ".$pieces[3]));