使用$ date = date('Y-m-d H:i:s',$ date)将问题从Y / m / d转换为Y-m-d;

I'm trying to convert the brackets to hyphens, but instead the date variable loses its value:

echo $date; // outputs 26/05/2015 10:41:56sd2

$date = date('Y-m-d H:i:s', $date);

echo $date; // outputs 969-12-31 18:00:26
  1. The second parameter to date() must be a Unix timestamp. You're giving it a string.

  2. That date format is invalid and won't work with strtotime() anyway. When you use / as the date separator US format is assumed. There is no 26th month.

  3. The last three characters of that is not valid in any standard that I know of and will break any date function unless you specifically account for it (which you can't do with date() or strtotime())

Use DateTime::createFromFormat() to do this:

$date = DateTime::createFromFormat('d/m/Y H:i:s???', '26/05/2015 10:41:56sd2');
echo $date->format('Y-m-d H:i:s');

Demo