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
mister whitemister white 

Display Day

Hello. Sorry if this seems like a stupid question but it's been driving me crazy. I've tried different formulas and nothing seems to work. 

 

I have a report that shows created cases and its set in the Matrix format. I have the opened date on the left. When I choose a grouping type and choose day I get the date and not the day of the week. I also try to group by "Calendar Day in Month" but still can't get the graph to report the actually day of the month. 

 

Any help would be greatly appreciated. Thank you. 

 

 

Also, i get the following when trying to use the date formula. 

 

Error: Invalid custom summary formula definition: Formula result is data type (Text), incompatible with expected data type (Number).

 

Shashikant SharmaShashikant Sharma

Hi I can give you this java script method that returns the day

 

 

	function finddate( month, xday, year )

    {



     var days = new Array()

	days[0]  = 31;

	days[1]  = 28;

	days[2]  = 31;

	days[3]  = 30;

	days[4]  = 30;

	days[5]  = 30;

	days[6]  = 31;

	days[7]  = 31;

	days[8]  = 30;

	days[9]  = 31;

	days[10] = 30;

	days[11] = 31;

	

	var monthdat = new Array()

	monthdat[0]  = "January";

	monthdat[1]  = "February";

	monthdat[2]  = "March";

	monthdat[3]  = "April";

	monthdat[4]  = "May";

	monthdat[5]  = "June";

	monthdat[6]  = "July";

	monthdat[7]  = "August";

	monthdat[8]  = "September";

	monthdat[9]  = "October";

	monthdat[10] = "November";

	monthdat[11] = "December";



	var daydata = new Array()

	daydata[0] = "Sunday";

	daydata[1] = "Monday";

	daydata[2] = "Tuesday";

	daydata[3] = "Wednesday";

	daydata[4] = "Thursday";

	daydata[5] = "Friday";

	daydata[6] = "Saturday";



     var currentdate = new Date();





	if ( year%4 == 0 )

	  { 

	    leap = 1;

	  }

	else

	  {

	    leap = 0;

	  }



	days[1] = 28 + leap;

	

     if( (xday < 0)  ||  (xday > days[month-1]) )

      {

       msgstring = "Improper day for " + monthdat[month-1] + "; try again."

       alert( msgstring );

       return;

      }	





	if( month > 2 )

	  {

	   jy = year;

	   jm = month + 1;

	  }

	else

      {

	   jy = year  -  1;

	   jm = month + 13;

	  }



	jday   = Math.floor( 365.25*jy ) + Math.floor( 30.6001*jm ) + 1720995 + xday;

	ja     = Math.floor( 0.01 * jy );

	jday   = jday + 2 - ja + Math.floor( 0.25*ja );

	theday = ( 1 + jday )%7;







     currday   = currentdate.getDate();

     currmonth = currentdate.getMonth() + 1;

     curryear  = currentdate.getYear();  





     if( curryear > 90 )

      { offsetyr = 1900; }

     else

      { offsetyr = 2000; }



     curryear = curryear + offsetyr;





     later = 0;

     if( year > curryear )

      { later = 1; }

     if( (year == curryear) && (month > currmonth) )

      { later = 1; }

     if( (year == curryear) && (month == currmonth) && (xday > currday) )

      { later = 1; }



     if ( later == 0 )

      {

	  resultstring = monthdat[month-1] + " " + xday + ", " + year + " was a " + daydata[theday];

      }

     else

      {

	  resultstring = monthdat[month-1] + " " + xday + ", " + year + " will be a " + daydata[theday];

      }



	alert( resultstring );



     }

 In this leap year calculation is not right 

Update this to calculate it rightly as 1900 will be a leap year by this but it is not.

Any year which has last 2 digits 00 like 1600,1800, 1900, 2000, are divided by 400 not by 4, update this logic and you will get the Day

 

if(year%4 == 0)

 

Shashikant SharmaShashikant Sharma

Use this one your formula field which should  have return type 'Text'

 

IF(MOD(DateFieldAPIName__c - DATE(0001,1,1) , 7) == 0 , 'Saturday' , IF(MOD(DateFieldAPIName__c- DATE(0001,1,1) , 7) == 1 , 'Sunday' , 
IF(MOD(DateFieldAPIName__c- DATE(0001,1,1) , 7) == 2 , 'Monday' , 
IF(MOD(DateFieldAPIName__c- DATE(0001,1,1) , 7) == 3 , 'Tuesday' , 
IF(MOD(DateFieldAPIName__c- DATE(0001,1,1) , 7) == 4 , 'Wednesday' , 
IF(MOD(DateFieldAPIName__c- DATE(0001,1,1) , 7) == 5 , 'Thursday' , 
IF(MOD(DateFieldAPIName__c- DATE(0001,1,1) , 7) == 6 , 'Friday' , 'No Day')))))) 
)

 

You can also Use Case instead of IF in formula like this :

 

CASE(MOD(DateFieldAPIName__c - DATE(0001,1,1) , 7) , 0 , 'Saturday' , 1 , 'Sunday' ,  2 , 'Monday' , 3 , 'Tuesday' , 4 , 'Wednesday' , 5 , 'Thursday' , 6 , ' Friday'  , 'No Day Found')

 

To see more on this how to calculate day in Apex Class see : 

http://forceschool.blogspot.com/2011/06/calculate-day-of-date-in-apex.html

Ankit AroraAnkit Arora

A bit more optimized formula :)

 

 

CASE(MOD( TODAY() - DATE(1900, 1, 7), 7), 
0, "Sunday", 1, "Monday", 2, "Tuesday", 3, 
"Wednesday", 4, "Thursday", 5, "Friday", 6, 
"Saturday","Error")

 

Thanks
Ankit Arora

 

Arun Garg 9Arun Garg 9
Use this formula field which should  have return type 'Text' of DayName
https://sfdcadda.blogspot.in/2017/05/insert-day-name-by-providing-date-using.html
Blog