我为我的用户提供了一个搜索页面,我希望他们能够做的一件事是使用时间范围在我们的数据库中搜索项目。
目前,我的查询如下所示:
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) between '1:00:00' 和 '16:00:00')' 时,它会显示结果。这可能与查询开头的 date_format 有什么关系吗?