How to find the number of days for a month using Apex in Salesforce?

How to find the number of days for a month using Apex in Salesforce?

Date.daysInMonth() can be used to find the number of days for a month using Apex in Salesforce.

Sample Code:

Integer numberDays = 
    Date.daysInMonth(
        2014, 
        2
    );
System.debug(
    'No of days in this month is ' + 
    numberDays
);

Output:

Leave a Reply