0

我昨天设置了这个旋转日历,我想我可能会遇到问题,今天果然出现了我预期的问题。当日子改变时,日期也随之改变。它不像昨天那样跳过周末,而是显示星期六而不是星期一。它只假设显示周一 - 周五和 +3 并返回周一 - 周五。示例代码:

echo "Today";
echo date('m/d'); 
echo "<br>";
echo substr(date('l/m/d', strtotime('+1 day')), 0, 2). date('m/d', strtotime('+1 day')); 
echo "<br>";
echo substr(date('l/m/d', strtotime('+2 day')), 0, 1). date('m/d', strtotime('+2 day'));
echo "<br>";
echo substr(date('l/m/d', strtotime('+5 day')), 0, 1). date('m/d', strtotime('+5 day'));
echo "<br>";
echo substr(date('l/m/d', strtotime('+6 day')), 0, 1). date('m/d', strtotime('+6 day'));
echo "<br>";
echo substr(date('l/m/d', strtotime('+7 day')), 0, 1). date('m/d', strtotime('+7 day'));
echo "<br>";
echo substr(date('l/m/d', strtotime('+8 day')), 0, 2). date('m/d', strtotime('+8 day'));
echo "<br>";
echo substr(date('l/m/d', strtotime('+9 day')), 0, 1). date('m/d', strtotime('+9 day'));
echo "<br>";
echo substr(date('l/m/d', strtotime('+12 day')), 0, 1). date('m/d', strtotime('+12 day'));
echo "<br>";
echo substr(date('l/m/d', strtotime('+13 day')), 0, 1). date('m/d', strtotime('+13 day'));

显然模式没有完成工作,我如何确保总是跳过周末?

此外,我将其连接到这样的 sql 查询中:(实际代码)

sum(case when cast(a.follow_up as date)=cast(GETDATE() as date) then 1 else 0 end) 'Today<br>&nbsp;" . date('m/d') . "',
        sum(case when DATEDIFF(dd,cast(GETDATE() as date),cast(a.follow_up as date))='1' then 1 else 0 end) '" . substr(date('l/m/d', strtotime('+1 day')), 0, 2).'<br>' . date('m/d', strtotime('+1 day')) . "',
        sum(case when DATEDIFF(dd,cast(GETDATE() as date),cast(a.follow_up as date))='2' then 1 else 0 end) '" . substr(date('l/m/d', strtotime('+2 day')), 0, 1).'<br>' . date('m/d', strtotime('+2 day')) . "',
        sum(case when DATEDIFF(dd,cast(GETDATE() as date),cast(a.follow_up as date))='3' then 1 else 0 end) '" . substr(date('l/m/d', strtotime('+5 day')), 0, 1).'<br>' . date('m/d', strtotime('+5 day')) . "',
        sum(case when DATEDIFF(dd,cast(GETDATE() as date),cast(a.follow_up as date))='4' then 1 else 0 end) '" . substr(date('l/m/d', strtotime('+6 day')), 0, 1).'<br>' . date('m/d', strtotime('+6 day')) . "',
        sum(case when DATEDIFF(dd,cast(GETDATE() as date),cast(a.follow_up as date))='5' then 1 else 0 end) '" . substr(date('l/m/d', strtotime('+7 day')), 0, 1).'<br>' . date('m/d', strtotime('+7 day')) . "',
        sum(case when DATEDIFF(dd,cast(GETDATE() as date),cast(a.follow_up as date))='6' then 1 else 0 end) '" . substr(date('l/m/d', strtotime('+8 day')), 0, 2).'<br>' . date('m/d', strtotime('+8 day')) . "',
        sum(case when DATEDIFF(dd,cast(GETDATE() as date),cast(a.follow_up as date))='7' then 1 else 0 end) '" . substr(date('l/m/d', strtotime('+9 day')), 0, 1).'<br>' . date('m/d', strtotime('+9 day')) . "',
        sum(case when DATEDIFF(dd,cast(GETDATE() as date),cast(a.follow_up as date))='8' then 1 else 0 end) '" . substr(date('l/m/d', strtotime('+12 day')), 0, 1).'<br>' . date('m/d', strtotime('+12 day')) . "',
        sum(case when DATEDIFF(dd,cast(GETDATE() as date),cast(a.follow_up as date))='9' then 1 else 0 end) '" . substr(date('l/m/d', strtotime('+13 day')), 0, 1).'<br>' . date('m/d', strtotime('+13 day')) . "',
4

1 回答 1

1

date('N') 将以 1-Monday 到 7-Sunday 的格式给出星期几
所以如果我们减去 1 得到 0-6,然后用它来返回日期,它将带我们回到上周一.

即 monday=1, 1-1=0, -0days 是星期一
tuesday=2, 2-1=1, -1days 是星期一
..
friday=5, 5-1=4 -4days 是星期一

$lastmonday=strtotime("-".(date("N")-1)." days");
for($loop=0;$loop<14;$loop++)
{
    $theday=strtotime("+".$loop." days", $lastmonday);
    if(date("N", $theday)>5)
    {
       echo 'weekend';
    }
    else
    {
        echo date('D m/d'); 
    }
    echo "<br>";
}
于 2013-05-01T17:18:10.293 回答