0

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.

din
  • 25
  • 1
  • 6

2 Answers2

1
$pieces = explode(" ", $start);
$new_date_in = date("Y-m-d",strtotime($pieces[2]." ".$pieces[1]." ".$pieces[3]));
Jirka Hrazdil
  • 3,983
  • 1
  • 14
  • 17
0

You're using the wrong pieces and passing 08 Mar Wed. strtotime() is pretty good. Just use $start:

$new_date_in = date("Y-m-d", strtotime($start));
AbraCadaver
  • 78,200
  • 7
  • 66
  • 87