Get Last day of Month

Get Last day of a month (28, 29, 30 or 31)?

Formula

DAY(ADDMONTHS(DATE(YEAR(DateField__c), MONTH(DateField__c),1),1)-1)


The trick here is to take the 1st of the month and year of the date field, add 1 month to it and subtract 1 day.

For example, if my date field is March 3rd 2022, the formula will add 1 month to March 1st 2022 and will return April 1st 2022. We then subtract 1 day to get March 31st 2022.


Comments

Popular Post

How to use Comparable Interface in Salesforce

Update Contact Mailing Address with Account Billing Address on Custom Button

Salesforce Spring 16 Release Exam (Maintenance Exam Q&A) for Developer 201 Admin