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
B2AB2A 

Formula field to calculate amount of days in the next month

I'm not even sure if apex trigger is required for this, since formula fields could possibly do this.  Just wondering whether someone has done this or not.

 

The calculation/value currently should equal "31" since next month has that many days (August). 

 

Any help would be great.

 

Thanks.

Best Answer chosen by Admin (Salesforce Developers) 
JavajJavaj

 Hi 

 

To calculate the number of days in current month, use this following formula

 

     DAY(DATE(YEAR(TODAY()),MONTH(TODAY())+1,1)-1)

 

 

For next month :

 

    DAY(DATE(YEAR(TODAY()),MONTH(TODAY())+2,1)-1)

 

  let me know if you have any issues. 

 

 

All Answers

kamlesh_chauhankamlesh_chauhan

Hi,

May be this will solve your issue. Use following formula in your object with number type formula field.

CASE(MONTH(TODAY()),
1, IF(MOD(YEAR(TODAY()),100)==0 && MOD(YEAR(TODAY()),400)==0, 29, if(MOD(YEAR(TODAY()),4)==0,29,28)), 2, 31,
3, 30,
4, 31,
5, 30,
6, 31,
7, 31,
8, 30,
9, 31,
10, 30,
11, 31,
12, 31,
0)

JavajJavaj

 Hi 

 

To calculate the number of days in current month, use this following formula

 

     DAY(DATE(YEAR(TODAY()),MONTH(TODAY())+1,1)-1)

 

 

For next month :

 

    DAY(DATE(YEAR(TODAY()),MONTH(TODAY())+2,1)-1)

 

  let me know if you have any issues. 

 

 

This was selected as the best answer