上周日期阵列(起始最新星期一) [英] Array of last week dates (starting for latest monday)

查看:134
本文介绍了上周日期阵列(起始最新星期一)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要生成一个报告,该报告将包括从星期一上周开始数据(如果今天是星期一,那么只显示当天的日期和数量)。
我可以知道我如何能得到的最后一个星期日期阵列(从上周一开始)?
谢谢你。

I have to generate a report, which will consist data for last week starting from monday (if today is monday, then only display the today's date and count). Can I know how can I get the last week dates array(starting from last monday)? Thanks.

我写,但在这种情况下,如果上周开始日期是31,然后第二天变为32,这是不可能的。

I wrote this, but in this case if last week start date is 31, then the next day becomes 32, which is not possible.

$last_week_date_start = date('Y-m-d', strtotime('last monday')) + 1;

我想日期的数组。
谢谢你。

I want a array of dates. Thanks.

推荐答案

里面添加+1

for($i=0; $i<6; $i++){
    $last_week_dates[] = date('Y-m-d', strtotime('last monday + '.$i.' day'));
}

/*
array(7) {
  [0]=>
  string(10) "2012-08-20"
  [1]=>
  string(10) "2012-08-21"
  [2]=>
  string(10) "2012-08-22"
  [3]=>
  string(10) "2012-08-23"
  [4]=>
  string(10) "2012-08-24"
  [5]=>
  string(10) "2012-08-25"
  [6]=>
  string(10) "2012-08-26"
}
*/

这篇关于上周日期阵列(起始最新星期一)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆