datetime以yyyy-mm-dd hh:mm:ss格式的字符串来保存数据;
date则是只有年月日以yyyy-mm-dd形式的字串;
timestamp类型和php中的timestamp类型名字一样,但是两者基本上是不同的。
php是延用了unix时间签的类型为一个整数,
而在mysql中timestamp字段则是随着记录变化而一个自动更新为当时时间的datetimp字段。在mysql4.1版本之后timestamp格式datetime格式基本上是一致了。
于是常常需要在php和msql中对两种格式的timestamp进行转换。转换方法总结一下:
第一种方法:使用 date()和strtotime()函数
$mysqltime=date('y-m-d h:i:s',$phptime);
$phptime=strtotime($mysqldate);
第二种方法:在查询语句中使用mysql函数转换:unix_timestamp(datetime=>php timestamp)和from_unixtime(php timestamp=>datetime).
$sql=select unix_timestamp(datetimefield) from table where ...;
$sql=update table set datetimefield=from_unixtime($phptime) where ..;
第三种方法:就是mysql中使用整数字段来保存php的timestamp类型。
