Sunday, January 13, 2013

String to MySQL date format in PHP

String to Date in PHP

Sometimes when I export some MS Excel/ MS Access data to MySQL , It is required to convert some date in string to MySQL compatible date format. You can use DateTime class to convert the string to date in any format you want. The code is below.
function _mk_date($str)
 $temp = new DateTime($datestr);
 return date_format($temp, 'Y-m-d');

No comments:

Post a Comment