查询以从过去24小时内创建的数据库中选择记录 [英] Query to select records from a database that were created within the last 24 hours

查看:99
本文介绍了查询以从过去24小时内创建的数据库中选择记录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道如何查询数据库以显示过去24小时内提交的结果。



在表中, topic ,我有一个collumn设置为 start_date ,它使用时间戳。如何查询数据库以查找在过去24小时内创建的主题?



基本上,我想这样做,但不知道如何使用 WHERE

  $ query = mysql_query(SELECT * FROM topics WHERE start_date = 'LAST 24 HOURS?'); 

感谢:)

解决方案

您可以尝试这样的操作;

  $ query = mysql_query(SELECT * FROM topics WHERE start_date = DATE_ADD(NOW(),INTERVAL -1 DAY)); 


已编辑 NOW - 60 * 60 * 24 错了。抱歉。


I am wondering how to query to the database to show results that have been submitted in the last 24 hours.

In the table, topics, I have a collumn set up called start_date which uses timestamps. How would I query the database to find the topics created in the last 24 hours?

Basically, I want to do something like this, but not sure how to use WHERE:

 $query = mysql_query("SELECT * FROM topics WHERE start_date = 'LAST 24 HOURS?'");

Thanks :)

解决方案

You can try with something like this;

$query = mysql_query("SELECT * FROM topics WHERE start_date = DATE_ADD(NOW(), INTERVAL -1 DAY)");

Edited: the math of NOW() - 60*60*24 was wrong. Sorry.

这篇关于查询以从过去24小时内创建的数据库中选择记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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