1、首先是我们分析datetime长度是8个字节,INT的长度是4个字节,存储空间上比datatime少。
2、int存储索引的空间也比datetime少,排序效率高,查询速度比较快。
3、方便计算,unix时间戳有点就是方便计算。
网上还有还一个TIMESTAMP 和INT比较的例子,timestamp效率比int不会差,而且timestamp有自动更新功能
相同点
TIMESTAMP列的显示格式与datetime列相同。
换句话说,显示宽度固定在19字符,并且格式为YYYY-MM-DD HH:MM:SS。
不同点
datetime
以”YYYY-MM-DDHH:MM:SS”格式检索和显示datetime值。支持的范围为”1000-01-01 00:00:00″到”9999-12-31 23:59:59″
TIMESTAMP值不能早于1970或晚于2037
TIMESTAMP
1、4个字节储存(Time stamp value is stored in 4 bytes)
2、值以UTC格式保存( it stores the number of milliseconds)
3、时区转化 ,存储时对当前的时区进行转换,检索时再转换回当前的时区。
datetime
1、8个字节储存(8 bytes storage)
2、实际格式储存(Just stores what you have stored and retrieves thesamething which you have stored.)
3、与时区无关(It has nothing to deal with the TIMEZONEandConversion.)