这是我的查询:
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>
它似乎运行不佳,我不确定为什么。 我认为这与 last_modified 列的原始格式有关
更新
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>
最佳答案
使用 str_to_date(last_modified,'%m/%d/%Y')
而不是 str_to_date(last_modified,'%M %d,%Y')
关于php - 使用自定义日期检索最近 3 年的数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34321923/