1000字范文,内容丰富有趣,学习的好帮手!
1000字范文 > php mysql 时间字段_php – MySQL中各种日期/时间字段类型的优...

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

时间:2018-07-10 06:15:28

相关推荐

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 | 0122174108 |

+----+--------+----------------+

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 | 0122174123 |

+----+---------+----------------+

1 row in set (0.00 sec)

mysql>

> DATETIME是日期和时间的标准数据类型,它与MySQL中的日期和时间函数一起使用.我可能在实践中使用它

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

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。