我的查询是
select *
from emp
where DATE_FORMAT(approved_date,'%d-%m-%Y')BETWEEN '01-01-2014' and '26-01-2014';
但它显示了2013年的记录。
表格是批准日期:
01-10-2013
01-01-2014
25-2-2014
答案 0 :(得分:3)
试试这个:
select * from emp
where approved_date
BETWEEN STR_TO_DATE('18-01-2014', '%d-%m-%Y')
AND STR_TO_DATE('26-01-2014', '%d-%m-%Y')
答案 1 :(得分:1)
dd-mm-yyyy格式
select * from emp
where approved_date > STR_TO_DATE('2014-01-01','%d-%m-%Y') and
approved_date < STR_TO_DATE('2014-01-25','%d-%m-%Y');
您也可以使用Between Too
select * from emp
where approved_date BETWEEN STR_TO_DATE('2014-01-01','%d-%m-%Y')
AND STR_TO_DATE('2014-01-25','%d-%m-%Y');
答案 2 :(得分:0)
示例示例:
SELECT users.* from users
WHERE created_at >= '2011-12-01'
AND created_at <= date_add('2011-12-01', INTERVAL 7 DAY)Which will select all users in the same interval You might also find the BETWEEN operator more readable:
或
SELECT users.* from users
WHERE created_at BETWEEN('2011-12-01', date_add('2011-12-01', INTERVAL 7 DAY));
希望这会有所帮助..