SELECT *
FROM tbl_problem
WHERE user_id = 1
AND problem_solved != -1
AND problem_timestamp BETWEEN '20110212' AND DATE('20110212', INTERVAL 14 DAY)
ORDER BY problem_id
问题是20110212是由php动态生成的,这就是我使用DATE / INTERVAL COMBO的原因。
我想要做的是在2周的时间范围内选择条目,因为你知道这两周周期的开始日期。
提前致谢
答案 0 :(得分:0)
为什么不让PHP重新格式化然后查询
SELECT *
FROM tbl_problem
WHERE user_id = 1
AND problem_solved != -1
problem_timestamp > '2011-01-24' AND problem_timestamp < DATE_ADD('2011-02-12', INTERVAL 14 DAY)
ORDER BY problem_id
要将PHP中的日期从当前格式转换为MYSQL格式,请使用
$date = date_create_from_format('Ymd', '20110212');
$mysqlDate = date_format($date, 'Y-m-d'); //2011-01-24
答案 1 :(得分:0)
使用Datediff。
SELECT *
FROM tbl_problem
WHERE user_id = 1
AND problem_solved != -1
AND DATEDIFF(problem_timestamp,'20110112') <= 14
ORDER BY problem_id