note 7504 deleted from time by jmcastagnetto
| From: | jmcastagnetto@php.net | Date: | Fri, 08 Sep 2000 18:04:03 +0000 |
| Subject: | note 7504 deleted from time by jmcastagnetto | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-4547@lists.php.net to get a copy of this message | ||
You can also use the following function to convert a MySQL TIMESTAMP field to a Unix epoch-based
timestamp, if you don't trust the time() function:
///////////////////////////////////////////////////////////
// mysql_to_unix_time: converts a 14-digit MySQL //////////
// timestamp to a UNIX timestamp //////////////////////////
///////////////////////////////////////////////////////////
/*
$datetime should be a number in the format yyyymmddhhmmss
Returns the date's UNIX timestamp
*/
function mysql_to_unix_time ($datetime) {
// Convert to string so we can reliably parse it
settype($datetime, 'string');
// Break the number up into its components (yyyymmddhhmmss)
// storing results in the array matches
eregi('(....)(..)(..)(..)(..)(..)',$datetime,$matches);
// Pop the first element off the matches array. The first
// element is not a match, but the original string, which
// we don't want.
array_shift ($matches);
// Transfer the values in $matches into labeled variables
foreach
(array('year','month','day','hour','minute','second')
as $var) {
$$var = array_shift($matches);
}
return mktime($hour,$minute,$second,$month,$day,$year);
}