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
Mikeb66Mikeb66 

Formula field (Date)

I would like to create a custom field that always displays the last day of the month of the close date. Any ideas on how to create this formula?
Best Answer chosen by Admin (Salesforce Developers) 
mpannmpann

Mike,

 

when you say last day of the month, you mean the date? You could do it like this:

 

IF(MONTH( CloseDate ) = 12,DATE(YEAR( CloseDate),12,31),
DATE(YEAR( CloseDate),MONTH( CloseDate)+1,1)-1 )

 

That takes care of leap years, too.

 

Marc

 

 

All Answers

mpannmpann

Mike,

 

when you say last day of the month, you mean the date? You could do it like this:

 

IF(MONTH( CloseDate ) = 12,DATE(YEAR( CloseDate),12,31),
DATE(YEAR( CloseDate),MONTH( CloseDate)+1,1)-1 )

 

That takes care of leap years, too.

 

Marc

 

 

This was selected as the best answer
teacup13teacup13
Can someone please help me with formular for counting weekdays in a month/ year? In another word, the number of days bt start date and end date in a week/ month/ year. -Thx!
Mikeb66Mikeb66

Thanks, that worked perfectly.

 

Any suggestion on how to display the Close Month as the Month Name and not just the first day of the month?

mpannmpann

Sure.In a Formula (text) field you can do this.

 

CASE (MONTH(CloseDate),

"1","January",

"2","February",

.

.

"12","December",

"")

 

Unfortunately, you can not change the format of a Date field directly like in Excel for example.