note 77649 deleted from function.time by sobak

From: Date: Thu, 01 Dec 2016 13:53:24 +0000
Subject: note 77649 deleted from function.time by sobak
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-207859@lists.php.net to get a copy of this message
Note Submitter: by225 at yahoo dot com ---- A function for converting to Unix time without using the MySQL UNIX_TIMESTAMP function in a query (MySQL allows eight different formats for timestamps): <?php function UnixTime($mysql_timestamp){ if (preg_match('/(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})/', $mysql_timestamp, $pieces) || preg_match('/(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})/', $mysql_timestamp, $pieces)) { $unix_time = mktime($pieces[4], $pieces[5], $pieces[6], $pieces[2], $pieces[3], $pieces[1]); } elseif (preg_match('/\d{4}\-\d{2}\-\d{2} \d{2}:\d{2}:\d{2}/', $mysql_timestamp) || preg_match('/\d{2}\-\d{2}\-\d{2} \d{2}:\d{2}:\d{2}/', $mysql_timestamp) || preg_match('/\d{4}\-\d{2}\-\d{2}/', $mysql_timestamp) || preg_match('/\d{2}\-\d{2}\-\d{2}/', $mysql_timestamp)) { $unix_time = strtotime($mysql_timestamp); } elseif (preg_match('/(\d{4})(\d{2})(\d{2})/', $mysql_timestamp, $pieces) || preg_match('/(\d{2})(\d{2})(\d{2})/', $mysql_timestamp, $pieces)) { $unix_time = mktime(0, 0, 0, $pieces[2], $pieces[3], $pieces[1]); } return $unix_time; } ?>

« previous php.notes (#207859) next »