从今天选择记录,本周本月,php mysql [英] Select records from today, this week, this month php mysql
本文介绍了从今天选择记录,本周本月,php mysql的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
date('Y-m-d H:i:s');
创建记录时,将输入日期。这是我到目前为止: 日期>(日期 - (60 * 60 * 24))
SELECT * FROM jokes WHERE date>(date-(60 * 60 * 24))ORDER BY score DESC
周日期>(日期 - (60 * 60 * 24 * 7))
code>SELECT * FROM jokes WHERE date>(date-(60 * 60 * 24 * 7))ORDER BY score DESC
月(30天)其中日期>(日期 - (60 * 60 * 24 * 30))
code>SELECT * FROM jokes WHERE date>(date-(60 * 60 * 24 * 30))ORDER BY score DESC
任何想法都将不胜感激。谢谢!
解决方案
假设你的日期列是一个实际的MySQL日期列:
SELECT * FROM jokes WHERE date> DATE_SUB(NOW(),INTERVAL 1 DAY)ORDER BY score DESC;
SELECT * FROM jokes WHERE date> DATE_SUB(NOW(),INTERVAL 1 WEEK)ORDER BY score DESC;
SELECT * FROM jokes WHERE date> DATE_SUB(NOW(),INTERVAL 1 MONTH)ORDER BY score DESC;
I imagine this is pretty simple, but can't figure it out. I'm trying to make a few pages - one which will contain results selected from my mysql db's table for today, this week, and this month. The dates are entered when the record is created with date('Y-m-d H:i:s');
. Here's what I have so far:
day where date>(date-(60*60*24))
"SELECT * FROM jokes WHERE date>(date-(60*60*24)) ORDER BY score DESC"
week where date>(date-(60*60*24*7))
"SELECT * FROM jokes WHERE date>(date-(60*60*24*7)) ORDER BY score DESC"
month (30 days) where date>(date-(60*60*24*30))
"SELECT * FROM jokes WHERE date>(date-(60*60*24*30)) ORDER BY score DESC"
Any ideas would be much appreciated. Thanks!
解决方案
Assuming your date column is an actual MySQL date column:
SELECT * FROM jokes WHERE date > DATE_SUB(NOW(), INTERVAL 1 DAY) ORDER BY score DESC;
SELECT * FROM jokes WHERE date > DATE_SUB(NOW(), INTERVAL 1 WEEK) ORDER BY score DESC;
SELECT * FROM jokes WHERE date > DATE_SUB(NOW(), INTERVAL 1 MONTH) ORDER BY score DESC;
这篇关于从今天选择记录,本周本月,php mysql的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文