检索不到一天的行 [英] Retrieve rows less than a day old
本文介绍了检索不到一天的行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个列date
,其默认值为CURRENT_TIMESTAMP
,例如:2011-11-16 15:34:02
.有什么方法可以在mysql语句中(而不是在php中)设置条件以检索少于一天的行?像这样:
I have a column date
, which has a default value of CURRENT_TIMESTAMP
, eg: 2011-11-16 15:34:02
. Is there any way to put a condition in the mysql statement (not in php) to retrieve rows which are less than a day old? Something like:
SELECT * FROM orders where date > 24 hours ago
推荐答案
You can use timestampadd()
to get the timestamp for 24 hours ago
SELECT * FROM orders WHERE `date` > timestampadd(hour, -24, now());
这等效于
SELECT * FROM orders WHERE `date` > timestampadd(day, -1, now());
这篇关于检索不到一天的行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文