查找日期早于 7 天后的记录.使用日期时间格式 [英] finding records that have dates that fall before the date 7 days from now. using datetime format

查看:30
本文介绍了查找日期早于 7 天后的记录.使用日期时间格式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试根据当前日期查找记录.我尝试做的查询之一是查找当前日期 7 天内的任何记录.这就是我所拥有的

I am trying to find records based on the current date. One of the queries I am trying to do is find any record that falls within 7 days of the current date. this is what I have

WHERE `Project`.`delivery_deadline` <= 'DATE_SUB(CURDATE(),INTERVAL 7 DAY)' 
GROUP BY `Project`.`id` 
LIMIT 20

这当然行不通.我到底做错了什么.Delivery_deadline 是日期时间格式而不是日期格式

This isn't working of course. what exactly am I doing wrong. delivery_deadline is datetime format not date format

推荐答案

你不应该写:

WHERE `Project`.`delivery_deadline` >= 'DATE_SUB(CURDATE(),INTERVAL 7 DAY)' 

编辑

正确的解决方法是:

WHERE Project.delivery_deadline between now() and date_add(now() ,interval 7 day)

这篇关于查找日期早于 7 天后的记录.使用日期时间格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆