2011-08-09 4 views
2

금요일이 금요일 인 경우 배송일을 다음 화요일로 변경해야합니다. 여기 내 코드가 있습니다.PHP 검사 특정 일

$tomorrow = mktime(0,0,0,date("m"),date("d")+$tt+1,date("Y")); 
$duedate = date("d - M D", $tomorrow); 
$str = substr($duedate, 9, 11); 
$fri='Fri'; 
$sat='Sat'; 
if(strcmp($str,$fri)==0) 
{ 
$tomorrow = mktime(0,0,0,date("m"),date("d")+4,date("Y")); 
$duedate = date("d - M D", $tomorrow); 
} 

는하지만 난 루프가 확인되지 않은 경우 금요일 correctly.So가 $tommorrow-4도하지 working.Any 포인터입니다 추가 생각하십니까?

답변

2
$tomorrow = mktime(0,0,0,date("m"),date("d")+$tt+1,date("Y")); 
$duedate = date("d - M D", $tomorrow); 
if (date("N", $tomorrow) == 5) { 
    $tomorrow = mktime(0,0,0,date("m"),date("d")+4,date("Y")); 
    $duedate = date("d - M D", $tomorrow); 
} 
3

이 충분해야한다 :

if (date('N') == 5) { 
    //set duedate to next Tuesday 
    $DateTime = new DateTime('now'); 
    $DateTime->add(new DateInterval('P4D')); //add 4 days 
    $dueDate = $DateTime->format('your format'); 
} 

N은 금요일 5 인 ISO 표준화 된 번호를 다시 제공합니다. Date는 두 번째 인수가 필요하지 않으며,이 경우 현재 시간 소인이 필요합니다.

DateTime에 대한 자세한 내용은 http://www.php.net/manual/en/book.datetime.php을 참조하십시오.

1

첫째, 예를 들어, 단지 날짜 기능을 사용하여 하루 추출 시도 :

date('D'); // Mon through Sun 

또는

date('N'); // 1 (for Monday) through 7 (for Sunday) 

이 두 번째로, 예를 들어, 날짜에 일을 추가 한 strtotime 함수를 사용하여 :

strtotime("+4 day",$date); // Add 4 days to date 
1
$nextTuesday = strtotime('next tuesday');