Home  >  Article  >  Backend Development  >  关于php-mysql中按日期排序的有关问题

关于php-mysql中按日期排序的有关问题

WBOY
WBOYOriginal
2016-06-13 13:06:191174browse

关于php-mysql中按日期排序的问题!
我在向数据库中插入日期字段time的时候用了strtotime,这样在数据库中显示的数据是这种形式的:1350489600。
然后我在order by time desc的时候发现了这样的问题:2000年02月07日竟然排在了2012年10月19日的前面,这是怎么回事呢?求大侠指教,我想让2012年10月19日排在第一位的。这两个日期的time值分别是949852800和1350576000。

------解决方案--------------------
估计,结果应该是一个字符串,而不是整数。
建议,使用time()直接获取一个时间戳。
------解决方案--------------------
949852800 2000年02月07日
1350576000 2012年10月19日

如果 time 数 int 类型 order by time desc 时必然是后者排在前边
------解决方案--------------------
因为你的 time 字段是 varchar 类型的,改成 int 型就好了。

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