例如
select date_format(date(credit_date),'%Y-%m-%d') from product where date(credit_date) >= date '2012-11-02' and date(credit_date) <= date '2013-11-02'
如何从 Date1 获取列到 Date2
Db Structure
+-----------------------------------------+
| credit_date |
+-----------------------------------------+
| 21/09/2013 |
| 22/09/2013 |
| 23/09/2013 |
| 24/09/2013 |
| 25/09/2013 |
| 26/09/2013 |
| 27/09/2013 |
| 28/09/2013 |
+-----------------------------------------+
答案 0 :(得分:0)
看起来你的credit_date是另一种日期格式的varchar类型,如果是这样的话,试试这个:
select date_format(str_to_date(credit_date,'%d/%m/%Y'), '%Y-%m-%d') as dt
from product
where str_to_date(credit_date,'%d/%m/%Y') >= '2012-11-02'
and str_to_date(credit_date,'%d/%m/%Y') <= '2013-11-02'
mysql的默认格式是Y-m-d,你不需要在where子句上转换它。除非您的数据库配置为具有特定格式。由于您的credit_date
似乎是一个varchar,您必须先将其转换为日期,然后对其进行测试。
在这里查看小提琴:http://sqlfiddle.com/#!2/8b379/9