2011-11-22 3 views
1

가능한 중복은 :
Get first day of week in PHP?PHP에서 주 시작하는 방법을 찾으려면?

내가 나에게 시작과 현재 주말의 제공이 스크립트를 가지고 :

$begweek = (date('l') == 'Monday')?date('Y-m-d'):date('Y-m-d',strtotime('last monday')); 
echo $begweek; 

echo "<br>"; 
$endweek = (date('l') == 'Sunday')?date('Y-m-d'):date('Y-m-d',strtotime('Sunday')); 
echo $endweek; 

은 내가 필요한 것은 방법이다 $date="2011-11-15"과 같이 임의의 날짜를 전달하면 매주의 시작과 끝을 찾을 수 있습니다.

이 변수를 수용하기 위해 현재 스크립트에서 수정해야 할 사항이 있습니까?

감사

+1

참조 : http://stackoverflow.com/questions/6202576/get-all-work-days-in-a-week-for-a-given-date/6202709#6202709 - 예 : http : // codeepad .viper-7.com/82ADWj – Gordon

+0

많은 중복이 있습니다. http://stackoverflow.com/search?q=first+day+of+week+php – Gordon

답변

2

날짜 함수는 제 2 모수 걸린다.

강령

function blah($date){ 

    $begweek = (date('l', strtotime($date)) == 'Monday')?date('Y-m-d', strtotime($date)):date('Y-m-d',strtotime('last monday', strtotime($date))); 
    echo $begweek; 

    echo "<br>"; 
    $endweek = (date('l', strtotime($date)) == 'Sunday')?date('Y-m-d', strtotime($date)):date('Y-m-d',strtotime('Sunday', strtotime($date))); 
    echo $endweek; 

} 

blah("2011-11-15"); 

출력물

2011-11-14
2011-11-20

0

date 타임 스탬프는를 얻기 위해 제 2 매개 변수를 날짜는

입니다.은 타임 스탬프를 얻습니다.

date('l', strtotime($date)); 
0
사용 '지난 월요일'

하지만 두 번째 매개 변수의로 단지 strtotime()에게 임의의 날짜의 타임 스탬프를 전달합니다.

+0

"last monday"는 $ date가 $ date 이전의 월요일 날짜를 반환합니다. 월요일 – Gordon

관련 문제