Home  >  Article  >  Backend Development  >  thinkphp时间段查询

thinkphp时间段查询

WBOY
WBOYOriginal
2016-06-23 14:00:321376browse

thinkphp时间段查询,比如查询2014-03-16 09:15:20到2014-04-16 09:15:20这个时间段内的数据


回复讨论(解决方案)

大神门来帮帮忙呀

假设你数据库存储时间的字段叫 time 格式是int 存储的是时间戳
可以这样查询

$t1 = 2014-03-16 09:15:20;$t2 = 2014-04-16 09:15:20;$timestart = strtotime($t1);$timeend = strtotime($t2);$model = M("你的数据表")$res = $model -> where("time >= $timestart  and time <= $timeend ")->select();


假设你数据库存储时间的字段叫 time 格式是int 存储的是时间戳
可以这样查询

$t1 = 2014-03-16 09:15:20;$t2 = 2014-04-16 09:15:20;$timestart = strtotime($t1);$timeend = strtotime($t2);$model = M("你的数据表")$res = $model -> where("time >= $timestart  and time <= $timeend ")->select();

如果时间格式是datetime格式呢?

datetime也支持大于小于,至少mysql和sql server都可以

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