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

标签 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>

它似乎运行不佳,我不确定为什么。 我认为这与 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/

相关文章:

javascript - 检查在输入框中输入的值是否等于某个值

php - 检索附件 Sendgrid 入站解析

php - 我如何跟踪访问者的国家并将他们重定向到适当的站点?

mysql插入行的时间太长

mysql - 如何从mysql数据库中选择键和值到json格式

php - 需要用户名和密码

php - 分页链接无效/页面/2 - 未找到 - Wordpress

phpmyadmin 错误 "#1062 - Duplicate entry ' 1' for key 1"

mysql - 在存储过程 MYSQL 中创建临时表

php - 当在不同页面上单击 anchor 标记时,如何更改 php 脚本中的 PHP 变量?