Convert MySQL date to UNIX timestamp

Here is a simple function to convert MySQL date format to UNIX timestamp


//UPDATE: There is more simple way to get same result

$mysqltime = '20101109140000';
$timestamp = strtotime($mysqltime);
echo date("Y-m-d H:i:s", $timestamp);

// from MySQL to UNIX timestamp
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;


Blinklist Blogmarks Digg Ma.gnolia My Web 2.0 Newsvine Reddit Segnalo Simpy Spurl Wists Technorati


Link Partners

Web Design Forum