MySQL中DATETIME跟TIMESTAMP的区别
MySQL中DATETIME和TIMESTAMP的区别 先Copy一份文档给大家看: DateTime A date and time combination. The supported range is '1000-01-01 00:00:00' to '9999-12-31 23:59:59'. MySQL displays DATETIME values in 'YYYY-MM-DD HH:MM:SS' format, but allow
MySQL中DATETIME和TIMESTAMP的区别先Copy一份文档给大家看:
DateTime
A date and time combination. The supported range is '1000-01-01 00:00:00' to '9999-12-31 23:59:59'.
MySQL displays DATETIME values in 'YYYY-MM-DD HH:MM:SS' format, but allows you to assign values to DATETIME columns using either strings or numbers.
TimeStamp
A timestamp. The range is '1970-01-01 00:00:00' to partway through the year 2037.
A TIMESTAMP column is useful for recording the date and time of an INSERT or UPDATE operation.
The first TIMESTAMP column in a table is automatically set to the date and time of the most recent operation if you don't assign it a value yourself.
You can also set any TIMESTAMP column to the current date and time by assigning it a NULL value.
DATETIME,字节数为8,取值范围为“1000-01-01 00:00:00——9999-12-31 23:59:59”
对应Java类型为java.sql.Timestamp
INSERT或UPDATE操作时系统不会自动修改其值,不可以设定默认值,为必须字段时必须手动插入,建议使用:new()
MySql按照YYYY-MM-DD HH:MM:SS对数据进行格式化,允许以字符串和数字的方式提交
eg:insert into time_table(CreateDate) values(‘2014-06-09
15:01:01’)
或insert into time_table(CreateDate) values(‘20140609150101’)
TIMESTAMP,字节数为4,取值范围为“19700101080001——20380119111407”
对应Java类型为java.sql.Timestamp
INSERT或UPDATE操作时(且未手动赋值)系统会自动更新、插入当前系统时间,默认值为CURRENT_TIMESTAMP()
提交手动赋值为NULL时也会被赋值为当前系统时间,错误时会填入0
使用TIMESTAMP一定要注意他的时间范围(见上)。
上一篇: hibernate4注解配置,纠结的一对多双向关联
下一篇: mysql数据库添加从库_MySQL
推荐阅读
-
细说PHP中strlen跟mb_strlen的区别
-
mysql中engine=innodb和engine=myisam的区别介绍_MySQL
-
apache日志中的日期格式怎么转换成mysql中的datetime
-
PHP中VC6 X86跟VC9 X86的区别及Non Thread Safe的意思
-
MySQL数据库中的Date,DateTime和TimeStamp类型详解_MySQL
-
PHP中addslashes与mysql_escape_string的区别分析
-
mysql中order by与group by的区别
-
MySQL中Decimal类型和Float Double的区别(详解)
-
mysql中engine=innodb和engine=myisam的区别 mysql问题
-
数据库 - Truncate/Delete/Drop区别及MySQL如何清空表中的数据