> TIMESTAMP存储在MySQL专有方法中(尽管它基本上只是一个由年,月,日,小时,分钟和秒组成的字符串),此外,只要插入或更改记录,TIMESTAMP类型的字段就会自动更新.显式字段值给出:
mysql> create table timestamp_test(
id integer not null auto_increment primary key,
val varchar(100) not null default '', ts timestamp not null);
Query OK, 0 rows affected (0.00 sec)
mysql> insert into timestamp_test (val) values ('foobar');
Query OK, 1 row affected (0.00 sec)
mysql> select * from timestamp_test;
+----+--------+----------------+
| id | val | ts |
+----+--------+----------------+
| 1 | foobar | 20090122174108 |
+----+--------+----------------+
1 row in set (0.00 sec)
mysql> update timestamp_test set val = 'foo bar' where id = 1;
Query OK, 1 row affected (0.00 sec)
Rows matched: 1 Changed: 1 Warnings: 0
mysql> select * from timestamp_test;
+----+---------+----------------+
| id | val | ts |
+----+---------+----------------+
| 1 | foo bar | 20090122174123 |
+----+---------+----------------+
1 row in set (0.00 sec)
mysql>
> DATETIME是日期和时间的标准数据类型,它与MySQL中的日期和时间函数一起使用.我可能在实践中使用它
>建议不要以INTEGER格式存储日期,因为由于时区,闰年等有趣的问题而打开真正的蠕虫病毒 – 至少如果您打算根据存储在该字段中的特定日期查询数据库.