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 posts from this blog

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

Show Hyper Link On Add Error in Salesforce Trigger

Show the Success Message before Redirecting the Detail page on Visualforce Page