I recently needed to get the day of the week from a Date in SalesForce and I was amazed to find that there’s no weekday() method on the date object; month: yes, day: yes, weekday: no.

Anyway I came up with the following addition to my AnotherBoringUtilClass:

private static integer getWeekday(Date input){
   return input.toStartOfWeek().daysBetween( input );
}

This will return a zero based day for the date you pass in where zero is the day that you have conifgured as the start of the week.

I have seen this done elsewhere in a slightly different way but I thought I’d share this one liner anyway.