我这里有一个获取所有日期的代码。我要实现的是获取每月的每周报告基础。我搜索了很多网站和论坛,但找不到任何东西。非常感谢与该问题有关的任何帮助。
$startOfWeek = date("Y-m-d", strtotime("Monday this week"));
$currentDayOfMonth=date('Y-m-01');
$maxDays=date('t');
for ($i=0; $i<$maxDays;$i++){
echo date("l, d M", strtotime($currentDayOfMonth . " + $i day"))."<br />";
}
这是上面代码的结果
Monday, 01 Apr
Tuesday, 02 Apr
Wednesday, 03 Apr
Thursday, 04 Apr
Friday, 05 Apr
Saturday, 06 Apr
Sunday, 07 Apr
Monday, 08 Apr
Tuesday, 09 Apr
Wednesday, 10 Apr
Thursday, 11 Apr
Friday, 12 Apr
Saturday, 13 Apr
Sunday, 14 Apr
Monday, 15 Apr
Tuesday, 16 Apr
Wednesday, 17 Apr
Thursday, 18 Apr
Friday, 19 Apr
Saturday, 20 Apr
Sunday, 21 Apr
Monday, 22 Apr
Tuesday, 23 Apr
Wednesday, 24 Apr
Thursday, 25 Apr
Friday, 26 Apr
Saturday, 27 Apr
Sunday, 28 Apr
Monday, 29 Apr
Tuesday, 30 Apr
我想要实现的是这样的
WEEK 1
Monday, 01 Apr
Tuesday, 02 Apr
Wednesday, 03 Apr
Thursday, 04 Apr
Friday, 05 Apr
Saturday, 06 Apr
Sunday, 07 Apr
WEEK 2
Monday, 08 Apr
Tuesday, 09 Apr
Wednesday, 10 Apr
Thursday, 11 Apr
Friday, 12 Apr
Saturday, 13 Apr
Sunday, 14 Apr
WEEK 3
Monday, 15 Apr
Tuesday, 16 Apr
Wednesday, 17 Apr
Thursday, 18 Apr
Friday, 19 Apr
Saturday, 20 Apr
Sunday, 21 Apr
WEEK 4
Monday, 22 Apr
Tuesday, 23 Apr
Wednesday, 24 Apr
Thursday, 25 Apr
Friday, 26 Apr
Saturday, 27 Apr
Sunday, 28 Apr
WEEK 5
Monday, 29 Apr
Tuesday, 30 Apr
您知道如何实现吗?
答案 0 :(得分:0)
您的意思是这样的吗?
$startOfWeek = date("Y-m-d", strtotime("Monday this week"));
$currentDayOfMonth=date('Y-m-01');
$maxDays=date('t');
for ($i=0, $week = 1; $i<$maxDays;$i++){
if ($i%7==0) {
if ($week > 1) echo "<br/>";
echo "WEEK " . $week++ . "<br/>";
}
echo date("l, d M", strtotime($currentDayOfMonth . " + $i day"))."<br />";
}
答案 1 :(得分:0)
检查日期是否可以被7整除并打印您的一周:
$startOfWeek = date("Y-m-d", strtotime("Monday this week"));
$currentDayOfMonth=date('Y-m-01');
$maxDays=date('t');
$weekNo = 1;
echo "WEEK 1";
for ($i=0; $i<$maxDays;$i++){
if (($i + 1)%7 == 0) {
$weekNo++;
echo "<br />WEEK ".$weekNo;
}
echo date("l, d M", strtotime($currentDayOfMonth . " + $i day"))."<br />";
}