我有一个mysql
Db,其中包含varchar
col(ArrangementDate),它包含日期:
我正在运行此查询:
select * from insolvenceyTestdetailstable
WHERE STR_TO_DATE( `ArrangementDate` , '%d/%m/%Y' ) BETWEEN '7/5/2009' AND '26/2/2016'
and ID > 0 LIMIT 50000;
但是在DB中它返回0结果我可以清楚地看到行:
27/2/2015
9/10/2013
9/10/2012
任何建议?
答案 0 :(得分:1)
问题应该是您比较的日期格式。
将'7/5/2009'
替换为2009-05-07
,将'26/2/2016'
替换为'2016-02-26'
您可以通过选择
查询来轻松测试有效日期select DATE('2015-02-27') as D1, DATE('27/2/2015') as D2; //D1 valid, D2 null
你的陈述应该是
select * from insolvenceyTestdetailstable
WHERE STR_TO_DATE( `ArrangementDate` , '%d/%m/%Y' ) BETWEEN '2009-05-07' AND '2016-02-26'
and ID > 0 LIMIT 50000;
答案 1 :(得分:0)
需要更多格式。
http://sqlfiddle.com/#!9/c898d1/6
select
*
from
insolvenceyTestdetailstable
WHERE
STR_TO_DATE(`ArrangementDate`,'%e/%c/%Y') BETWEEN STR_TO_DATE('7/5/2009','%e/%c/%Y') AND STR_TO_DATE('26/2/2016','%e/%c/%Y') and
ID > 0
LIMIT 50000