我有一个针对我的用户的搜索页面,我希望他们能够做的一件事是使用时间范围在我们的数据库中搜索项目。
目前,我的查询如下所示:
select ****
from ****
where created_on >='{$errTimeDayOne}' and created_on <= '{$errTimeDayTwo}'
所以,说$errTimeDayOne = 2013-03-24 00:00:00
和$errTimeDayTwo = 2013-04-01 01:00:00
它会在该范围之间进行搜索。我正在尝试在00:00:00 - 01:00:00
到日期2013-03-24 - 2013-04-01
之间进行搜索。有什么想法或建议吗?
更新
我的查询现在看起来像这样:
SELECT call_id, priority_name, caller_name,
cust_name, cust_rep, caller_dept,
DATE_FORMAT(created_on , '%Y-%m-%d') AS created_on,
DATE_FORMAT(updated_on, '%Y-%m-%d') AS updated_on,
source_name, created_by, cat_name, subcat_name
FROM calls INNER JOIN categories ON calls.cat_id =
categories.cat_id INNER JOIN ticket_priority ON
calls.ticket_priority = ticket_priority.priority_id
INNER JOIN ticket_source ON calls.ticket_source =
ticket_source.source_id LEFT OUTER JOIN subcategories
ON calls.subcat_id = subcategories.subcat_id WHERE
created_by = 'brett.little' AND (DATE(created_on)
between '2013-03-01' and '2013-08-01') AND
(TIME(created_on) between '1:00:00' and '16:00:00')
当我遗漏'(TIME(created_on)在'1:00:00'和'16:00:00'之间')时显示结果。这可能与查询开头的date_format有关吗?
答案 0 :(得分:1)
您必须加强该条款以分别检查时间和日期:
WHERE (DATE(created_on) BETWEEN '2013-03-24' and '2013-04-01')
AND (TIME(created_on) BETWEEN '00:00:00' AND '01:00:00')