选择今天、本周、本月的记录 php mysql

Select records from today, this week, this month php mysql(选择今天、本周、本月的记录 php mysql)
本文介绍了选择今天、本周、本月的记录 php mysql的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

我想这很简单,但无法弄清楚.我正在尝试制作几页 - 其中包含从我的 mysql db 表中选择的今天、本周和本月的结果.日期是在使用 date('Y-m-d H:i:s'); 创建记录时输入的.这是我到目前为止所拥有的:

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))

day where date>(date-(60*60*24))

 "SELECT * FROM jokes WHERE date>(date-(60*60*24)) ORDER BY score DESC"

日期所在的星期>(日期-(60*60*24*7))

week where date>(date-(60*60*24*7))

 "SELECT * FROM jokes WHERE date>(date-(60*60*24*7)) ORDER BY score DESC"

月(30天)其中日期>(日期-(60*60*24*30))

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!

推荐答案

假设您的日期列是实际的 MySQL 日期列:

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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

In PHP how can you clear a WSDL cache?(在 PHP 中如何清除 WSDL 缓存?)
failed to open stream: HTTP wrapper does not support writeable connections(无法打开流:HTTP 包装器不支持可写连接)
Stop caching for PHP 5.5.3 in MAMP(在 MAMP 中停止缓存 PHP 5.5.3)
Caching HTTP responses when they are dynamically created by PHP(缓存由 PHP 动态创建的 HTTP 响应)
Memcached vs APC which one should I choose?(Memcached 与 APC 我应该选择哪一个?)
What is causing quot;Unable to allocate memory for poolquot; in PHP?(是什么导致“无法为池分配内存?在 PHP 中?)