繁体   English   中英

PHP-MySQL查询-计算时间戳在特定日期(“ Ymd”)内的结果

[英]PHP - MySQL query - counting results where timestamp is within specific date (“Y-m-d”)

这是非常基本的MySQL,但我无法弄清楚这一点,以及如何正确执行。

示例:我有一个名为“ table1”的数据库表,其中包含用户访问者数据的记录列表。 栏:“ ID”,“ TM”和“ IP”

“ TM”包含记录存储时间的时间戳。

我有一个PHP代码,在其中循环从开始日期到当前日期的几天。 像这个例子:

// Start date
$startdateforarray = '2010-07-21';
// End date
$end_date = date("Y-m-d");

    while (strtotime($startdateforarray) <= strtotime($end_date)) {
        $timestamp = strtotime($startdateforarray);

    //Here I want to run my MySQL Query...

        $startdateforarray = date ("Y-m-d", strtotime("+1 day", strtotime($startdateforarray)));

}

现在,在循环中,我想进行查询以计算每天“ table1”中有多少个结果。

因此,MySQL查询应类似于:

"SELECT * FROM table1 WHERE TM = (day of $timestamp)" 

当然($ timestamp的一天)是我遇到的问题。 我知道这应该很简单,但是我还没有找到解决方案。

假设时间戳是指Unix时间戳,则可以

SELECT * FROM table1 WHERE FROM_UNIXTIME(TM,'%Y-%m-%d') =  '2010-07-21'

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM