Formatting dates has always been the bane of my existence and tonight, I couldn’t figure out how to calculate the day of the week based on a date when coding in apex on the Force.com platform. I found this wikipedia article: Calculating the day of the week and used it to build the following function.
This function will determine the day of the week for any date, including leap years. It can be cleaned up considerably but I figured I would share my geekery with you all in raw form. (Y3k bug: note the - 2000 to calculate the last two digits of the year.)
public String readableDay(Date dateToFormat)
{
String dayOfWeekString = '';
Integer day = dateToFormat.day();
Integer month = dateToFormat.month();
//Get last two digits of year
Integer twoDigitYear = dateToFormat.year() - 2000;
//Get first two digits of year
String centuryYear = String.valueOf(deadline.year());
centuryYear = centuryYear.substring(0,2);
Integer centuryYearInt = Integer.valueOf(centuryYear);
//Centuries: c = 2(3 - (century mod 4))
//century = last two numbers of the year
Integer modYear = math.mod(centuryYearInt, 4);
modYear = 3 - modYear;
Integer century = 2 * modYear;
System.debug('Century: ' + century);
//Years: y = year + (year / 4)
Integer years = twoDigitYear + (twoDigitYear / 4);
//Months (check if leap year)
Integer monthResult = 0;
if(month == 1)
{
if(math.mod(deadline.year(), 4) == 0)
monthResult = 6; //leap year
else
monthResult = 0; //not leap year
}
else if(month == 2)
{
if(math.mod(deadline.year(), 4) == 0)
monthResult = 2; //leap year
else
monthResult = 3; //not leap year
}
else if(month == 3)
monthResult = 3;
else if(month == 4)
monthResult = 6;
else if(month == 5)
monthResult = 1;
else if(month == 6)
monthResult = 4;
else if(month == 7)
monthResult = 6;
else if(month == 8)
monthResult = 2;
else if(month == 9)
monthResult = 5;
else if(month == 10)
monthResult = 0;
else if(month == 11)
monthResult = 3;
else if(month == 12)
monthResult = 5;
//Calculate Running Total
Integer runningTotal = century + years + monthResult + day;
//Calculate mod of week
Integer dayOfWeek = math.mod(runningTotal, 7);
//Day of Week Table
if(dayOfWeek == 0)
dayOfWeekString = 'Sunday';
else if(dayOfWeek == 1)
dayOfWeekString = 'Monday';
else if(dayOfWeek == 2)
dayOfWeekString = 'Tuesday';
else if(dayOfWeek == 3)
dayOfWeekString = 'Wednesday';
else if(dayOfWeek == 4)
dayOfWeekString = 'Thursday';
else if(dayOfWeek == 5)
dayOfWeekString = 'Friday';
else if(dayOfWeek == 6)
dayOfWeekString = 'Saturday';
return dayOfWeekString;
}

Two things I would have tried:
1. If you convert it to a DateTime then you could probably use DateTime.format to emit the day string.
2. You could also keep it as Date but subtract it from the beginning of the week (which presumably is a Sunday), like
date myDate = date.today();
date weekStart = myDate.toStartofWeek();
integer dayOfWeek=
weekStart.daysBetween(myDate);
Then you could apply your if statement to get the corresponding string.
I had thought of the second option but it won’t be reliable for an application that is meant to be used in places where the beginning of the week is not Sunday, but instead Monday.
toStartOfWeek: “Returns the start of the week for the Date that called the method, depending on the context user’s locale. For example, the start of a week is Sunday in the United States locale, and Monday in European locales.”
Here’s how I do it in formula fields:
CASE(MOD( Record_Date__c – DATE(1900, 1, 6), 7), 0, “Saturday”, 1, “Sunday”, 2, “Monday”, 3, “Tuesday”, 4, “Wednesday”, 5, “Thursday”, 6, “Friday”,”")
What about:
public String readableDay(Date d) {
Datetime dt = DateTime.newInstance(d.year(), d.month(), d.day());
return dt.format(‘EEEE’);
}