PHP date showing '1970-01-01 ' after conversion

AssamGuy picture AssamGuy · Jan 24, 2012 · Viewed 94.5k times · Source

I have a form in which date format is dd/mm/yyyy . For searching database , I hanverted the date format to yyyy-mm-dd . But when I echo it, it showing 1970-01-01 . The PHP code is below:

$date1 = $_REQUEST['date'];     
echo date('Y-m-d', strtotime($date1));

Why is it happening? How can I format it to yyyy-mm-dd?

Answer

Cyclonecode picture Cyclonecode · Jan 24, 2012

Replace / with -:

$date1 = strtr($_REQUEST['date'], '/', '-');
echo date('Y-m-d', strtotime($date1));