[thelist] Re: PHP/MySQL dates, times and autoincrements

jon steele jjsteele22 at yahoo.com
Sat Apr 27 18:16:01 CDT 2002


Here's an overview of timestamps in MySQL (from http://www.mysql.com/doc/D/A/DATETIME.html)

Column type	Display format
TIMESTAMP(14)	YYYYMMDDHHMMSS
TIMESTAMP(12)	YYMMDDHHMMSS
TIMESTAMP(10)	YYMMDDHHMM
TIMESTAMP(8)	YYYYMMDD
TIMESTAMP(6)	YYMMDD
TIMESTAMP(4)	YYMM
TIMESTAMP(2)	YY

You can convert mysql timestamps to unix timestamps quite easily in PHP:

<?
//function to convert dates of form YYYYMMDDHHMMSS to timestamp

function convertToTS($a){

$a = ''.$a.'';

$y = $a[0].$a[1].$a[2].$a[3];
$m = $a[4].$a[5];
$d = $a[6].$a[7];
$h = $a[8].$a[9];
$n = $a[10].$a[11];
$s = $a[12].$a[13];

return mktime($h, $n, $s, $m, $d, $y);
}
?>

Jon

__________________________________________________
Do You Yahoo!?
Yahoo! Health - your guide to health and wellness
http://health.yahoo.com



More information about the thelist mailing list