Home > Backend Development > PHP Tutorial > thinkphp时间段查询

thinkphp时间段查询

WBOY
Release: 2016-06-23 14:00:32
Original
1453 people have browsed it

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();
Copy after login
Copy after login


假设你数据库存储时间的字段叫 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();
Copy after login
Copy after login

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

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

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template