2011-07-18 12 views
3

これは次土曜日表示次の3土曜日

<?php echo date("l,j M Y", strtotime("next saturday")); ?> 

すなわち7月23日(土曜日)を示し、2011年、私はまた、2011年7月とそう

に土曜日30で、次の次の土曜日を表示したい

+0

質問は不完全です。 「これ」とは何を意味しますか? –

+0

*(参考)* http://php.net/manual/en/datetime.formats.relative.php – Gordon

答えて

10

、\日時と

strtotime("next saturday + 1 week") 
strtotime("next saturday + 2 weeks") 
... 
+0

もちろん、どこでも「週」を使用できます。 'strtotime("次の土曜日+ $週の週 ")' – Naltharial

+0

の日付( "Y-m-d"、strtotime( '土曜日+1週間')) –

0
$next_saturday = strtotime("next saturday"); 
$the_saturday_after_that = strtotime("next saturday", $next_saturday); 

...など。

2

PHP 5.2+を使用すると、次の3土曜日を取得するためにDateTimeDateIntervalを使用することができます。

例:また

<?php 

$date = new DateTime('next saturday'); 

// Loop 3 times. 
for ($i = 0; $i < 3; $i++) 
{ 
    echo $date->format('Y-m-d') . PHP_EOL; 

    // Add 1 month. 
    $date->add(new DateInterval('P7D')); 
} 
1

例:

/** 
* Get next three saturday 
* 
* @return \DateTime[] 
*/ 
function getNextThreeSaturday() 
{ 
    $count = 3; 
    $current = new \DateTime('saturday this week'); 

    $results = []; 
    for ($i = 0; $i < $count; $i++) { 
     $results[] = clone $current->modify('next saturday'); 
    } 

    return $results; 
} 
関連する問題