php mysql 时间字段_php – MySQL中各种日期/时间字段类型的优...

> 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格式存储日期,因为由于时区,闰年等有趣的问题而打开真正的蠕虫病毒 – 至少如果您打算根据存储在该字段中的特定日期查询数据库.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值