Convert MySQL date to UNIX timestamp

Submitted by:Jhon Smith

Date added:11 November, 2013

Category:PHP

PHP code to convert MySQL date to UNIX timestamp

Tags: convert mysql date , convert unix timestamp

Code Snippet:

    <?php
// 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;
}
?>
 
 

Comments