menu

Questions & Answers

Show next three saturday

this show the next Saturday

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

i.e Saturday,23 July 2011.

I want to show also the next next Saturday that is Saturday 30 july 2011 and so on

Comments:
2023-01-17 18:34:58
The question is incomplete. What do you mean by 'this'?
2023-01-17 18:34:58
Answers(4) :
$next_saturday = strtotime("next saturday");
$the_saturday_after_that = strtotime("next saturday", $next_saturday);

...and so on.

With PHP 5.2+, you can use DateTime and DateInterval to get the next 3 Saturdays:

Example:

<?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'));
}

Alternatively,

strtotime("next saturday + 1 week")
strtotime("next saturday + 2 weeks")
...
strtotime("next saturday + $weeks week")
Comments:
2023-01-17 18:34:58
date("Y-m-d",strtotime('Saturday +1 week'))
2023-01-17 18:34:58
today is saturday and i want next saturday date but it is showing next next saturday date

Example with \DateTime:

/**
 * 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;
}