Yet another blog
Day of week in apex code of Salesforce
I was looking out for way of getting the day of week of a particular date. On searching on the documentation i couldnt find a way of doing it.
Here is one way of doing it.
There is a function called toStartOfWeek() which 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. For example:
date myDate = date.today();
date weekStart = myDate.toStartofWeek();
Now we know the week start date which is going to Monday for European locales and Sunday for US locate. Now we can build up the weekdays for the rest of the week by adding 1 or the no of days, for example you add 2 days to weekstart to get the date for wednesday..
Also i am told there is a much simpler solution though i have not tried it myself.
String shortDayOfweek = DateTime.now().format(‘eee’); // ‘wed’