When working with Salesforce date formulas, we occasionally need to extract the year from a date.
For example, suppose we are tracking the Contract Start Date on the contract object, and we want to create a date formula field that only shows the year part of that date (like 2025) for reporting or grouping purposes.
In this article, we will learn the formula to extract the year from a date using the YEAR() function in Salesforce. Moreover, we will go through the steps to extract the year from the date Field in Salesforce.
Year Function in Salesforce Formula
In Salesforce, there are many scenarios where we need to extract the year from the date value, such as age calculation, event planning, and historical and financial analysis, to determine the validity and expiration of documents, etc.
And, in all these situations, we need to extract the year from the date in Salesforce. So, in Salesforce, we have the YEAR() function that we can use to extract the year from a given date.
Extract Year From Date Using Formula in Salesforce
Below, I will explain how we can extract the year from a given date so that it can be used in formulas, reports, or automation in Salesforce.
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 Contract Object.
In the Contract setup, click on the Fields and Relationships to create a new field and click the New button.
2. In this step, we are going to use a formula to extract the year from the given date and display it on the contract object. For that, select the option Formula from the data type and click Next.
3. Next, provide the Field Label and API Name for the formula field. Then, since we want to display only the year of the given date without a decimal point and comma separated, in the Formula Return Type, select Text and click on the Next button.
4. In the formula editor, enter the formula below and click the Next button.
Here, since we want to use the YEAR() function to extract the year from the date and the TEXT() function to display it in the text, we need to select the Advanced Formula.
Then select the Function from and click the Insert Selected button to use them. Then, to add the date field from the object.
You can see the Insert Field button as you click on it, you will see all fields from the contract object.
TEXT(YEAR( StartDate))
Provide this formula and click the Check Syntax button to confirm the formula is correct, and click the Next button.
5. 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.
6. 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.
We have now created the formula field that will return the year from the Contract Start Date field from the contract object.
As you navigate to the object, you will see the formula field that you created to extract and display the year from the contract start date.
In this way, we can create a formula field to store the extracted year from the given date in Salesforce.
Conclusion
I hope you have got an idea about how to extract and display the year from a date in Salesforce using the YEAR() function so that it can be used in formulas, reports, or automation in Salesforce.
You may like to read:
I am Bijay Kumar, the founder of SalesforceFAQs.com. Having over 10 years of experience working in salesforce technologies for clients across the world (Canada, Australia, United States, United Kingdom, New Zealand, etc.). I am a certified salesforce administrator and expert with experience in developing salesforce applications and projects. My goal is to make it easy for people to learn and use salesforce technologies by providing simple and easy-to-understand solutions. Check out the complete profile on About us.