$date = '30/03/2016'; echo date('Ym-d', strtotime($date)); 

Displays 1970-01-01. Is this the wrong date format for the strtotime() function?

    2 answers 2

    Well, not at all. strtotime understands a string of this format only in m/d/y or dmy

    If you want to use this line, you will need a mask:

     $date = DateTime::createFromFormat('d/m/Y', '30/03/2016'); 

    And then you can already rewrite to the output format you need:

     echo $date->format('Ym-d'); 

      From official documentation: http://php.net/manual/ru/function.strtotime.php

      Note: Dates in m / d / y or dmy format resolve ambiguity by analyzing the delimiters of their elements: if the delimiter is a slash (/), then the date is interpreted in the American m / d / y format, if the delimiter is a hyphen (-) or dot (.), then implies the use of the European d-my format. To avoid potential ambiguity, it is recommended to use dates in the ISO 8601 standard format (YYYY-MM-DD) or use the DateTime :: createFromFormat () function where possible.

      Decision:

       $date = '30/03/2016'; $date = str_replace('/', '-', $date); echo date('Ym-d', strtotime($date)); 
      • That is necessary, thanks! - quaresma89
      • Checked) a couple of minutes the delay was just - quaresma89