2011-08-09 11 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は第2引数を必要とせず、その場合は現在のタイムスタンプをとります。

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'); 
関連する問題