convert mysql date time to php timestamp

27 Mar

Sometimes you have no control over the format uses for dates in a database. Sometimes you have no control over the format returned by a function / class method. Hopefully this makes life easier

convert mysql date / time formats to unix timestamp during query

SELECT UNIX_TIMESTAMP(column_name) from TABLE

convert mysql date format to php timestamp

$php_timestamp=strtotime($mysql_date_format);

convert mysql datetime/timestamp to timestamp

credit: http://www.ryanbrill.com/

function convert_datetime($str) {

list($date, $time) = explode(‘ ‘, $str);
list($year, $month, $day) = explode(‘-’, $date);
list($hour, $minute, $second) = explode(‘:’, $time);

$timestamp = mktime($hour, $minute, $second, $month, $day, $year);

return $timestamp;
}

Comments are closed.