Counting rows where a timestamp is less than 24 hours old(计算时间戳小于 24 小时的行数)

本文介绍了计算时间戳小于 24 小时的行数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于下面的查询,我如何计算 datesent 小于 24 小时的行数?(字段 datesent 是一个时间戳).

For the query below, how could I count the number of rows where datesent is less than 24 hours old? (The field datesent is a timestamp).

提前致谢,

约翰

  $message = "SELECT datesent, recipient
               FROM privatemessage 
              WHERE recipient = '$u'";


  $messager = mysql_query($message);

$messagearray = array(); 

推荐答案

使用:

SELECT COUNT(*) AS cnt
  FROM PRIVATEMESSAGE pm
 WHERE pm.datesent >= DATE_SUB(NOW(), INTERVAL 1 DAY)

这篇关于计算时间戳小于 24 小时的行数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!