使用自定义日期检索最近3年的数据

时间:2015-12-16 20:53:50

标签: php mysql

这是我的疑问:

mysql> select * from jobs where datediff(now(),str_to_date(last_modified,'%M %d,%Y'))>=1095;

我得到0结果

的MySQL>从作业中选择max(last_modified);

+--------------------+
| max(last_modified) |
+--------------------+
| 9/9/2013           |
+--------------------+
1 row in set (0.06 sec)

mysql>

它似乎并没有很好地工作,我不知道为什么。 I think it has to do with the original formatting of the last_modified column

更新

mysql> select distinct(last_modified) from jobs where datediff(now(),str_to_date(last_modified,'%m/%d/%Y'))>=1095 limit 10;

+---------------+
| last_modified |
+---------------+
| 12/4/2003     |
| 12/5/2003     |
| 12/6/2003     |
| 12/8/2003     |
| 12/9/2003     |
| 12/10/2003    |
| 12/11/2003    |
| 12/12/2003    |
| 12/13/2003    |
| 12/14/2003    |
+---------------+
10 rows in set (0.00 sec)

mysql>

1 个答案:

答案 0 :(得分:5)

使用str_to_date(last_modified,'%m/%d/%Y')代替str_to_date(last_modified,'%M %d,%Y')