I hope this is elaborate enough... (yet commented enough). Have fun with it.
<?
// This uses variables pulled from the URL
// http://www.foo.com/test.php?month=7&day=14&year=2003
extract($_GET);
// Little check to see if we need to go to a previous year or not.
If ($month == '1'):
$prev_year = $year-1;
Else:
$prev_year = $year;
Endif;
// Numerical representation of the day of the week.
// In the case of July 14, 2003, this would give you a 1 (For Monday)
$firstdate = date ("w", mktime(0,0,0,$month,$day,$year));
// Get our day and month variables established (with leading zeros) for our query
$startday = date ("d", mktime(0,0,0,$month,($day-$firstdate),$year));
$startmonth = date ("m", mktime(0,0,0,$month,($day-$firstdate),$year));
$nowday = date ("d", mktime(0,0,0,$month,$day,$year));
$nowmonth = date ("m", mktime(0,0,0,$month,$day,$year));
// This isn't needed, but if you echo it out, you will see what is going on with this to verify that you have
// Sunday through the current day of the week.
$startdayname = date ("l", mktime(0,0,0,$month,($day-$firstdate),$year));
$nowdayname = date ("l", mktime(0,0,0,$month,$day,$year));
// Quick check of the startmonth, in case you are choosing January as the current month.
// This will set the $startmonth to 12 (for December)
If ($startmonth == '0'):
$startmonth = '12';
Endif;
// Compile the data into YYYY-MM-DD format for a comparison on a field that is in the Date format.
$startDate = $prev_year."-".$startmonth."-".$startday;
$endDate = $year."-".$nowmonth."-".$nowday;
// Just echoing the output, so you can see what's going on here.
echo $startDate." through ".$endDate." is a ".$startdayname." through a ".$nowdayname."!!!";
// Your query would go something like this (Obviously, you would need to set the connection and all first):
// I would avoid using a BETWEEN clause because if your date is on a Sunday, then a BETWEEN clause wouldn't produce any results.
$query = "SELECT * from WeeklyStats WHERE StatDate >= '$startDate' AND StartDate <= '$endDate'";
?>