This is a very quick note with the code to retrieve the full day name from a date (eg. "Monday").
Why?
If I use the toString() function to get the day, it only returns the first 3 letters of the day (eg. "Mon").
My_Date = today; Day_Name = My_Date.toString("E"); // returns "Mon"
- My_Date = today;
- Day_Name = My_Date.toString("E");  // returns "Mon"
Well a few methods.
Method #0: Update 2020
Tested in CRM and Creator and this is working:
My_Date = today; Day_Name = My_Date.toString("EEEE"); // returns "Monday"
- My_Date = today;
- Day_Name = My_Date.toString("EEEE");  // returns "Monday"
Method #1:
We're going to populate two arrays / lists; retrieve the index value; and use this in the second array as follows:
// lists Day_Names = List:String({"Monday","Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday"}); Day_Abbreviations = List:String({"Mon","Tue","Wed","Thu","Fri","Sat","Sun"}); // get date field day abbreviation Day_Abbreviation = My_Date.toString("E"); // find in array and return same index from first array Day_Name = Day_Names.get(Day_Abbreviations.indexOf(Day_Abbreviation));
- // lists
- Day_Names = List:String({"Monday","Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday"});
- Day_Abbreviations = List:String({"Mon","Tue","Wed","Thu","Fri","Sat","Sun"});
- // get date field day abbreviation
- Day_Abbreviation = My_Date.toString("E");
- // find in array and return same index from first array
- Day_Name = Day_Names.get(Day_Abbreviations.indexOf(Day_Abbreviation));
Day_Names = List:String({"Monday","Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday"}); Day_Abbreviations = List:String({"Mon","Tue","Wed","Thu","Fri","Sat","Sun"}); Day_Name = Day_Names.get(Day_Abbreviations.indexOf(My_Date.toString("E")));
- Day_Names = List:String({"Monday","Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday"});
- Day_Abbreviations = List:String({"Mon","Tue","Wed","Thu","Fri","Sat","Sun"});
- Day_Name = Day_Names.get(Day_Abbreviations.indexOf(My_Date.toString("E")));
Method #2:
Using a map, we can reduce this to two lines of code:
Day_Map = {"Mon":"Monday","Tue":"Tuesday","Wed":"Wednesday","Thu":"Thursday","Fri":"Friday","Sat":"Saturday","Sun":"Sunday"}; Day_Name = Day_Map.get(My_Date.toString("E"));
- Day_Map = {"Mon":"Monday","Tue":"Tuesday","Wed":"Wednesday","Thu":"Thursday","Fri":"Friday","Sat":"Saturday","Sun":"Sunday"};
- Day_Name = Day_Map.get(My_Date.toString("E"));
Method #3:
Using a list, the inevitable single line:
Day_Name = ",Sunday,Monday,Tuesday,Wednesday,Thursday,Friday,Saturday".toList(",").get(My_Date.toDate().getDayOfWeek());
- Day_Name = ",Sunday,Monday,Tuesday,Wednesday,Thursday,Friday,Saturday".toList(",").get(My_Date.toDate().getDayOfWeek());