You don't need "homemade-functions" to do that...
Check this:
$yr = date(Y);
$mnth = date(m);
$dy = date(d);
echo "base date: ".$yr."-".$mnth."-".$dy."<br>";
echo "last sunday: ".date("Y-m-d", mktime(0,0,0,$mnth,$dy-date("w",mktime(0,0,0,$mnth,$dy,$yr)),$yr))."<br>";
echo "next sunday: ".date("Y-m-d", mktime(0,0,0,$mnth,$dy+7-date("w",mktime(0,0,0,$mnth,$dy,$yr)),$yr))."<br>";
This is VERY simple example of what you can do with mktime... it takes todays date, finds LAST sunday and NEXT sunday...
Have fun 🙂
Hope it helps, Arni