php 查询当天的某一时刻范围内的数据怎么写?

WBOY
Release: 2016-06-23 13:37:50
Original
1225 people have browsed it

php连接mysql数据库要查询每天的某一时刻(或某几个时刻)范围内的数据,例如要查询当天17:25-17:35之间是否在数据库中接收到数据,应该怎么写?


回复讨论(解决方案)

select ... where 时间 between 起始 and 结束

select * from table where addtime>=' ?始??' and addtime

我只查当天的数据,楼上的写法把数据库这段时刻的所有数据都查到了。

select ... where 时间 between 起始 and 结束


“时间”当天的数据怎么写?
“起始与结束”的时间只有时分秒怎么写?
我要查询每天这个时间点范围内的数据,而不是特定某一天的数据。

select * from table where addtime>=' ?始??' and addtime
我只查当天的数据,当天的数据怎么写?
“起始与结束”的时间只有时分秒怎么写?
我要查询每天这个时间点范围内的数据,而不是特定某一天的数据。

DATE_FORMAT()成你要的时间格式,再去查询。不过效率会低


select * from table where addtime>=' ?始??' and addtime
我只查当天的数据,当天的数据怎么写?
“起始与结束”的时间只有时分秒怎么写?
我要查询每天这个时间点范围内的数据,而不是特定某一天的数据。



$starttime = '17:25:00';
$endtime = '17:35:00';

$sql="select * from table where addtime>='".date('Y-m-d').' '.$starttime."' and addtime

原来楼主的日期和时间是分两个字段存放地,那你得用日期+时间组成一个新值,用日期+时间>='?始日期??'  and 日期+时间



select * from table where addtime>=' ?始??' and addtime
我只查当天的数据,当天的数据怎么写?
“起始与结束”的时间只有时分秒怎么写?
我要查询每天这个时间点范围内的数据,而不是特定某一天的数据。



$starttime = '17:25:00';
$endtime = '17:35:00';

$sql="select * from table where addtime>='".date('Y-m-d').' '.$starttime."' and addtime
非常感谢版主,已经OK了,请问这方面的知识应该从哪些书,或者百度什么才能找到,我刚开始学,我找的书和视频只讲基本的查询,插入,删除操作,进一步详细的都没有。

#3 我只查当天的数据,楼上的写法把数据库这段时刻的所有数据都查到了。
#4 我要查询每天这个时间点范围内的数据,而不是特定某一天的数据。

那么你究竟要查什么呢?




select * from table where addtime>=' ?始??' and addtime
我只查当天的数据,当天的数据怎么写?
“起始与结束”的时间只有时分秒怎么写?
我要查询每天这个时间点范围内的数据,而不是特定某一天的数据。



$starttime = '17:25:00';
$endtime = '17:35:00';

$sql="select * from table where addtime>='".date('Y-m-d').' '.$starttime."' and addtime
非常感谢版主,已经OK了,请问这方面的知识应该从哪些书,或者百度什么才能找到,我刚开始学,我找的书和视频只讲基本的查询,插入,删除操作,进一步详细的都没有。

看看一些?源系?的源?。
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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!