In Salesforce, we sometimes need to determine the last day of a month based on a given date. For example, if a campaign has an End Date of 21st August 2025, we may want to know the 31st August 2025 (the last day of that month).
Salesforce does not provide a standard field to display a date like this, so we need a formula to calculate it. We can use a Salesforce Formula Field to find the last day of the month by using the date functions available in advanced formulas.
In this article, we will learn about how to get the last day of the month using a Salesforce formula. In this, I will create and explain a formula using functions that returns the last day of the month.
Salesforce Formula to Get Last Day of the Month
Below, I will explain the formula and the steps to get the last day of the month from any date in Salesforce. For this, we will use the Salesforce Date(), Today(), Year(), and Month() functions.
After creating the formula, when we provide any date, the formula will return the last date of the provided date’s month. Below, I have provided examples:
- End Date = 15-Aug-2025 -> Last Day of Month = 31-Aug-2025.
- End Date = 12-Feb-2024 -> Last Day of Month = 29-Feb-2024 (Leap Year).
1. Go to the Gear Icon. -> Click on the Setup. -> Select the Object Manager tab. Select the Object on which you want to create the Formula Field to extract the year from the date. Here, I’m going to create a Campaign Object.
- In the Campaign setup, click on the Fields and Relationships to create a new field and click the New button.

- In this step, we will use a formula to calculate and display the last date of the month from the given date and display it on the campaign object. For that, select the option Formula from the data type and click Next.
