I’m wanting to write a script that pulls in today’s date and then outputs the date of the next sunday from today’s date. Has anyone done this before?
Yep. There are better ways to do this involving the DateTime object but this works:
function getNextSunday()
{
$date = time();
$secondsPerDay = 60 * 60 * 24;
// If today happens to be Sunday
if (date('w',$date) == 0) $date += $secondsPerDay;
// Go to sunday
while(date('w',$date) != 0) $date += $secondsPerDay;
// Skip a week
$date += ($secondsPerDay * 7);
return date('Ymd',$date);
}
echo date('d-m-Y', strtotime('next sunday'));
Edit>>
I had expected something totally different in this topic when I read the title. I’m a little disappointed :o