note 77649 added to function.time

From: Date: Thu, 06 Sep 2007 19:32:51 +0000
Subject: note 77649 added to function.time
Groups: php.notes 
Request: Send a blank email to php-notes+get-130272@lists.php.net to get a copy of this message
A function for converting to Unix time without using the MySQL UNIX_TIMESTAMP function in a query (MySQL allows eight different formats for timestamps): 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; } ---- Server IP: 69.147.83.197 Probable Submitter: 75.41.115.138 ---- Manual Page -- http://www.php.net/manual/en/function.time.php Edit -- https://master.php.net/note/edit/77649 Del: integrated -- https://master.php.net/note/delete/77649/integrated Del: useless -- https://master.php.net/note/delete/77649/useless Del: bad code -- https://master.php.net/note/delete/77649/bad+code Del: spam -- https://master.php.net/note/delete/77649/spam Del: non-english -- https://master.php.net/note/delete/77649/non-english Del: in docs -- https://master.php.net/note/delete/77649/in+docs Del: other reasons-- https://master.php.net/note/delete/77649 Reject -- https://master.php.net/note/reject/77649 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#130272) next »