Take a look at the date() function. Here are a few examples.
$date = 20050301;
//nr of the week (in this case 9)
echo date(W,strtotime($date));
//numeric representation of the day of the week, this will output 2 (tuesday)
//Note: 0 is sunday and 6 is saturday
$day_nr = date(w,strtotime($date));
echo $day_nr;
//calculate nr of days left to next sunday
if($day_nr){
$sunday_nr = 7 - $day_nr; //If it's not a sunday, calculate how many days to next sunday
}else{
$sunday_nr = 0; //If it is a sunday, it is 0 days to sunday...
}
//Echos the date on sunday (20050306), the same week as 20050301
echo "sunday: ".date("Ymd",strtotime($date + $sunday_nr));