dream6120 2014-12-03 08:47
浏览 50

从开始日期到结束日期,打印第三个变量的计数

I have a start date as current date, which is stored in an array and the date 5 days back which is the end date.

Suppose the start date is 2014-12-03 and end date is 2014-11-28, so I have to print the count of a variable resulting from foreach, $value->user_source_history_date

And the process should run till the defined number lets say 30, where there are 30 dates in an array.

for($i=0; $i<=30; $i++)
{
$temp = strtotime("-5 days")
$dates = date("Y-m-d" , $temp)

}

Here I am iterating through 30 days, to get blocks of 5 days.

Lets say from a start date and end date, in the database field, user_source_history_dates, there are some 10 entries. So I need that count i.e 10 And the entries look like this:

2014-12-02 16:07:42
2014-12-02 16:07:42
2014-12-02 16:07:42
2014-12-02 16:07:42
2014-11-29 13:22:31
2014-11-29 13:22:31
2014-11-29 13:22:31

The start date would be 2014-12-03 and the end date would be 2014-11-28. So from the data above, I should get the count as 7.

My problem is how should I increment the count of $value->user_source_history_date

Also one of the problem is when the loop iterates, the end date previous iteration should become start date of next iteration.

One thing that I can do is use SQL query to get the data from a particular date block. Say something like this:

SELECT * FROM events WHERE datum BETWEEN '2011-4-6' AND '2011-4-12';
  • 写回答

1条回答 默认 最新

  • duandian8251 2014-12-03 09:05
    关注

    Based on OP comment, I hope I undersood him:

    for ($i = 0; $i <= 30; $i++) {
        $temp = strtotime("-5 days");
        //Store dates in an array
        $dates[] = date("Y-m-d", $temp);
    }
    echo "The cound of dates: " . count($dates)."<br />";
    var_dump($dates);
    
    评论

报告相同问题?

悬赏问题

  • ¥15 mmocr的训练错误,结果全为0
  • ¥15 python的qt5界面
  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀