查找最近24小时内有日期字段的记录 [英] Find records with a date field in the last 24 hours

查看:143
本文介绍了查找最近24小时内有日期字段的记录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的SQL查询中,如何在最近24小时内找到记录?
例如

In my SQL query how do i make it find the records in the last 24 hours? Eg

   SELECT * FROM news WHERE date < 24 hours

我通常通过将变量设置为date() - 1天,并将其与但是我想知道sql查询方式是否更快?

I usually do it by setting a variable to date() - 1 day and comparing it to that but I wondered whether the sql query way was faster?

推荐答案

您只需选择高于当前时间的日期减1一天。

You simply select dates that are higher than the current time minus 1 day.

SELECT * FROM news WHERE date >= now() - INTERVAL 1 DAY;

这篇关于查找最近24小时内有日期字段的记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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