Strtotime () & date () weird behavior when converting dates to the same format as before

I need to convert the date format to mm-dd-yyyyI don’t know which format of the current date is dynamic, so if I have a dynamic date format already in mm-dd-yyyy, then the function date()returns below outout   

    $date='02-13-2011';
    echo date('m-d-Y',strtotime($date));

conclusion

  01-01-1970

?>

http://codepad.org/AFZ6jel7

So I need to check if the date is already in mm-dd-yyyy, and then not apply date formatting. Is there any other way to do this? another parameter in these functions or something similar can be passed.

Thank.

+3
source share
2 answers

I strongly suspect this is causing the problem:

m/d/y d-m-y , : (/), m/d/y; (-) (.), d-m-y.

( strtotime.)

, d-m-y, 13 , , .

, , PHP:

  • , , ,
  • , d-m-y m-d-y
+7

- / m-d-Y .

echo date('m-d-Y',strtotime(str_replace('-', '/', $date)));
+4

Source: https://habr.com/ru/post/1794359/