Home  >  Article  >  Backend Development  >  mysql数据库表示时间的字段为什么可以用int类型啊这样与datetime相比有什么好处?该怎么处理

mysql数据库表示时间的字段为什么可以用int类型啊这样与datetime相比有什么好处?该怎么处理

WBOY
WBOYOriginal
2016-06-13 10:15:262082browse

mysql数据库表示时间的字段为什么可以用int类型啊,这样与datetime相比有什么好处?
我看到一些mysql数据库的设计,比如phpwind论坛的表示时间的字段,用int(10) ? 表示,表示时间本来就有datetime类型啊,为什么要用int型呢?这样做有什么好处啊,希望大哥们指点一二,感激涕零~

------解决方案--------------------
如果考虑有时区问题的就用int型的..
如果考虑读取方便的就用datetime型的...
------解决方案--------------------
因为 ? phpwind排序是用最后发表时间lastpost
数据量大时候int型比varchar快很多

------解决方案--------------------
可能的优点:
1、好排序,比如,我要最新新闻记录,只要排序desc就行了
2、方便转换,因为INT是在mysql ? 里,存的是时间戳。就不用格式转换了。否则,PHP和mysql里的时间是不一样的,存取要转换。
用inT,数据库就不用动了,格式化在 ? php进行。
3、方便时间计算。unix时间优点就是方例计算。

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn