在SQL中重现日期格式[重复]

This question already has an answer here:

I have a string of dates in php (dd/mm/yyyy) that I want to convert to yyyy-mm-dd format.

I have tried :

UPDATE `table` SET `DATE_VAR` = convert(datetime,'19/03/2015', 121) WHERE `ID`=160

Can you help me?

</div>

If you want to do the date conversion in PHP. Then one of the solutions could be:

$originalDate = str_replace('/', '-', "19/03/2015");
$newDate = date("Y-m-d", strtotime($originalDate)); // This is your mysql compatible date...

You can use $newDate variable in query.

UPDATE `table` SET `DATE_VAR` = '$newDate' WHERE `ID`=160

object oriented style:

echo DateTime::createFromFormat('d/m/Y', $date)->format('Y-m-d');

where $date is the date in dd/mm/yyyy format.