2011-07-18 15 views
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 +,你可以使用DateTimeDateInterval,以獲得未來3星期六:

例子:

<?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; 
} 
相關問題