If I have a PHP string in the format of mm-dd-YYYY (for example, 10-16-2003), how do I properly convert that to a Date and then a DateTime
mm-dd-YYYY
Date
DateTime
Like we have date "07/May/2018" and we need date "2018-05-07" as mysql compatible
if (!empty($date)) { $timestamp = strtotime($date); if ($timestamp === FALSE) { $timestamp = strtotime(str_replace('/', '-', $date)); } $date = date('Y-m-d', $timestamp); }
It works for me. enjoy :)