Salesforce Formula to Get Last Day of The Month : Bijay Kumar

Salesforce Formula to Get Last Day of The Month
by: Bijay Kumar
blow post content copied from  SalesForce FAQs
click here to view original post



### Summary of Content In Salesforce, when you need to find the last day of a month based on a specific date (like determining the last day of August 2025 from an end date of August 21, 2025), you can use a formula since Salesforce doesn’t have a built-in field for this purpose. This article explains how to create a formula field using several date functions: `DATE()`, `Today()`, `Year()`, and `Month()`. The formula calculates the last day of the month for any given date. For example, if the end date is August 15, 2025, the formula will return August 31, 2025. If the end date is February 12, 2024, it will return February 29, 2024, accounting for leap years. ### Steps to Create the Formula Field 1. **Access Setup**: Click the Gear Icon, select Setup, and go to the Object Manager. 2. **Select Object**: Choose the object (like Campaign) where you want to create the formula field. 3. **Create New Field**: Under Fields and Relationships, click New, then select Formula as the data type. 4. **Field Configuration**: Provide a Field Label and API Name, select Date as the return type, and proceed to the formula editor. 5. **Enter Formula**: Use the following formula to calculate the last day of the month: ``` DATE(YEAR(EndDate), MONTH(EndDate) + 1, 1) - 1 ``` This formula extracts the year and month from the End Date, adds one month, sets the day to the first of that month, and then subtracts one day to get the last day of the previous month. 6. **Check Syntax**: Validate the formula, set field-level security, and choose visibility options on page layouts. 7. **Save**: Click Save to create the formula field. After completing these steps, the new formula field will display the last date of the month corresponding to the End Date in the Campaign object. ### Conclusion This guide helps you create a formula in Salesforce to determine the last day of the month from a given date. The formula can be useful in various Salesforce reports and automation tasks. ### Additional Information - **Related Topics**: You may find it helpful to read about extracting the year from a date, date formula functions, or adding days to a date in Salesforce. - **Use Cases**: This formula can be particularly useful for campaign management, financial reporting, and any scenario where month-end dates are important. ### SEO Hashtags #Salesforce #SalesforceFormula #DateFunctions #LastDayOfMonth #CampaignManagement #SalesforceTips #SalesforceAutomation #SalesforceReporting #CRM #SalesforceDevelopment


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.

    Salesforce Formula Field Creation
    1. 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.
      Create Formula to Find Last Day in Salesforce
      1. Next, provide the Field Label and API Name for the formula field. Then, since we want to display the last date of the given date, in the  Formula Return Type, select Date and click on the Next button.
      Salesforce Formula Calculate Last Date
      1. In the formula editor, enter the formula below and click the Next button.
        • Here, we want to use the DATE() function to check the year and month of a given date. We need to select the Advanced Formula.
        • Then select the Function from and click the Insert Selected button to use them. Then, add the date field from the object.
        • Clicking the Insert Field button displays all fields from the campaign object. Here, we need to add an End Date field to display the last date of the month.
      DATE (
          YEAR ( EndDate),
          MONTH ( EndDate ) + 1, 1 ) - 1

      Let’s understand the above formula to return the last date of the month:

      • Here, using the YEAR() and MONTH() functions, we are extracting the year and month of the given date.
      • Then, in the extracted month, we add one more month. For example, if the extracted month is August (08), we add one month, resulting in September (09).
      • Then we set the 1st date for the new month. As per our example, 1st September.
      • Then we will subtract 1 Day from the 1st date of the new month. Here, 1st September – 1 Day = Last Day of previous month.
      • Provide this formula and click the Check Syntax button to confirm the formula is correct, and click the Next button.
      Create Formula to Find Last Date Using Salesforce
      1. Select the Field Level Security for the formula field, and select the profiles to make the field visible for the profiles. The field will be visible for the profiles selected from the Visible column.
        • After selecting the profiles, click on the Next button.
      Add Field Level Security for Fields in Salesforce
      1. In this step, we must select the field’s visibility on the object’s page layouts. In this case, we have created the formula field for the reports so we can choose not to display it on the page layouts.
        • Uncheck the checkboxes of the page layouts to prevent the field from displaying on them. After this, click on the Save button.
      Add Formula Field on Page Layout in Salesforce
      1. We have now created the formula field that will return the last date of the End Date field from the campaign object.
        • As you navigate to the object, you will see the formula field that you created to calculate and display the last date from the campaign end date.
      Create Date Formula in Salesforce
      Salesforce Formula to Get Last Day of the Month

      In this way, we can create a formula field to store the extracted last date of the given date month in Salesforce.

      Conclsuion

      I hope you have an idea about how to get the last day of the month using a Salesforce formula with the DATE() function, so that it can be used in formulas, reports, or automation in Salesforce. In this, I have created and explained a formula using functions that returns the last day of the month.

      You may like to read:

      The post Salesforce Formula to Get Last Day of The Month appeared first on SalesForce FAQs.


      August 21, 2025 at 06:49PM
      Click here for more details...

      =============================
      The original post is available in SalesForce FAQs by Bijay Kumar
      this post has been published as it is through automation. Automation script brings all the top bloggers post under a single umbrella.
      The purpose of this blog, Follow the top Salesforce bloggers and collect all blogs in a single place through automation.
      ============================

      Salesforce