Friday 19 September 2014

How to get the total number of days of month from the given date in Salesforce


Some time you may need to calculate the total number of Days in a month from the given input date.  For example suppose if the given date is 05/04/2014(DD/MM/YYYY) means the total number of days in a month will need to return as 31 Days. This can be done by using daysInMonth method.

daysInMonth - Returns the number of days in the month for the specified year and month (1=Jan) the following example finds the number of days in the month of February in the year 1960.


Here is the sample code,

1Date d = System.today();
2Integer numberDays = date.daysInMonth(d.Year(), d.Month());
3System.debug(numberDays);

No comments:

Post a Comment

Activities: Assign Tasks to a Queue Salesforce Lightning

Salesforce announced to assign Tasks to a Queue beginning from Spring'20 release. How does it work? In Setup, enter Queues in th...