cpcdev
cpcdev

Reputation: 1214

Get the date of the Saturday after next Sunday

I have the following code and everything is working fine except for $the_saturday_after_next_sunday. It is not outputting the correct date. Can you please help me display the date correctly?

Thanks for the help.

<?php
$today = date('m/d/Y');
$next_sunday = date('m/d/Y', strtotime("next Sunday"));
$the_saturday_after_next_sunday = date('m/d/Y', strtotime("next Saturday", $next_sunday));

echo "today is: " . $today . "<br>";
echo "next sunday is: " . $next_sunday . "<br>";
echo "the saturday after next sunday is: " . $the_saturday_after_next_sunday . "<br>";
?>

I've also tried

$the_saturday_after_next_sunday = strtotime("next Saturday", $next_sunday); 

Upvotes: 0

Views: 4421

Answers (2)

blamonet
blamonet

Reputation: 660

Try this:

strtotime("next Saturday", strtotime($next_sunday))

Instead of:

strtotime("next Saturday", $next_sunday)

Upvotes: 1

powtac
powtac

Reputation: 41040

$sunday   = strtotime("next Sunday");
$saturday = $sunday + 60 * 60 * 24 * 6;
echo date('m/d/Y', $saturday);

This works since PHP 4.4, see http://3v4l.org/SUnaR

Upvotes: 3

Related Questions