2013-05-01 4 views
0

어제이 회전 달력을 설정했는데 문제가 발생할 수 있으며 문제가 발생할 수 있다고 생각했습니다. 오늘 문제가 발생했습니다. 날짜가 바뀌면 날짜가 바뀌 었습니다. 어제처럼 주말을 뛰어 넘는 대신 월요일이 아닌 토요일을 보였다. 월요일 ~ 금요일, +3시, 월요일 ~ 금요일까지만 표시하는 것으로 가정합니다. 예제 코드 :php date 함수와 주말에 주말을 계산하는 요일을 계산하지 않아야합니다.

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 쿼리에이 concating 해요 : (실제 코드)

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')) . "', 
+1

', strtotime으로는 월요일입니다 ", $ lastmonday); – Waygood

+0

"l/m/d "를 자르지 않고'date ("D m/d ");를 쓸 수 있습니다. – Waygood

+0

그 대답은 제가 좋은 방법일지도 모릅니다. 그것에게 가라. 고맙습니다. –

답변

1

날짜 ('N') 7 일 - 월요일에게 형식으로 요일을 줄 것이다 -unday
그래서 1을 빼면 0-6이되고, 다시 사용하면 지난 월요일로 되돌아갑니다. 월요일 = 1, 1-1 = 0, 즉 -0days

월요일
..
금요일 = 5, 5-1 = 4된다 화요일 = 2, 2-1 = 1이다 월요일
-1days `다음`사용, 월요일에 다시 한 strtotime을 당신을 데려 갈 것이다 ("+ 일일 (.."- - "(날짜 ("N ") 1)"일 ") -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>"; 
} 
관련 문제