Getting day of the week in Apex

One of the most common function available in other languages for date variables is the one for getting the date of the week. Unfortunately Apex as of version 26 doesn't have it natively. One easy way to get the day of the week is by first converting a date into a datetime variable and then using the DateTime format to get the equivalent date.

Date mydate = Date.newInstance(2012,11,1);
Datetime dt = DateTime.newInstance(mydate, Time.newInstance(0, 0, 0, 0));
String dayOfWeek=dt.format('EEEE');
System.debug('Day : ' + dayOfWeek);

Output:

Day : Thursday

Visit the SimpleDateFormat Documentation to learn more about the DateTime.format function