function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
apaiapai 

Date Method to get day of the week

Best Answer chosen by Admin (Salesforce Developers) 
bob_buzzardbob_buzzard

It depends on which timezone you are in - I seem to recall that some calendars start the week on Sunday and some on Monday.

 

If you are after the day of the week, is there any reason why you wouldn't use the 'EEEE' format?

 

E.g. in the system log:

 

 

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

 

 

Gives the output:

 

 

09:39:41.034|USER_DEBUG|[3]|DEBUG|Day : Tuesday

 

 

All Answers

bob_buzzardbob_buzzard

If you put your date into a datetime, you can use the format method to generate a string containing the day of the week.

 

E.g. if you have your date in a variable called theDate:

 

 

DateTime dt=DateTime.newInstance(theDate, Time.newInstance(0, 0, 0, 0));
String dayOfWeek=dt.format('eee');

 

 

apaiapai

ok. I tested the following in the system log window:

 

Datetime dt = DateTime.newInstance(Date.today(), Time.newInstance(0, 0, 0, 0));
String dayOfWeek=dt.format('d');
System.debug('Day : ' + dayOfWeek);

 

The output value is 2. Does 2 correspond to Monday ?

bob_buzzardbob_buzzard

It depends on which timezone you are in - I seem to recall that some calendars start the week on Sunday and some on Monday.

 

If you are after the day of the week, is there any reason why you wouldn't use the 'EEEE' format?

 

E.g. in the system log:

 

 

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

 

 

Gives the output:

 

 

09:39:41.034|USER_DEBUG|[3]|DEBUG|Day : Tuesday

 

 

This was selected as the best answer
Shawn TaylorShawn Taylor

// In the class we defile the select statement that will pull the date in question. in my example im pulling the max Meeting date from a custome object called Governance_Decision__c

 

try{

tempARObj = [

SELECT MAX(CFARR_Meeting_Date__c) maxMeetingDate FROM Governance_Decision__c WHERE Project_Name__c IN:idSet];

meetingDate = Date.valueOf(tempARObj.get('maxMeetingDate'));

 

}

catch(Exception e) {

meetingDate = null;

}

 

//Ok, so lets display it on the screen. here is the code for the page

<apex:outputText value="{0,date,EEEE DDDD, MMMM, YYYY}"><apex:param value="{!meetingDate}"/></apex:outputText>

 

//Result: Tuesday, February 05, 2013

 

I hope this helps

Shawn,