Extract Year from Date Salesforce Formula

In this Salesforce Tutorial, we will learn the formula to extract Year from Date in Salesforce. Moreover, we will go through the steps using which we can extract Year from Date Field in Salesforce Lightning and Salesforce Classic.

In Salesforce, there are many scenarios where we need to extract the year from the date value in Salesforce, such as age calculation, event planning so that we don’t get messed with holidays, historical, financial analysis, and 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, If you want to explore How to Extract Year from Date in Salesforce Lightning and Classic Edition, you have come to the right place.

The following are the topics that we will cover in this Salesforce Tutorial:

  • Extract Year from Date using Advance Formula
  • How to extract Year from Date in Salesforce Lightning
  • How to extract Year from Date in Salesforce Classic

Extract Year from Date using Advance Formula

In Salesforce, to extract the year from the date value, we use the Salesforce Year() function.

Here is the syntax to extract Year from Date in Salesforce:

YEAR(date_field)

If, you want to learn in detail about YEAR() function, click Date Formula Functions in Salesforce.

How to extract Year from Date in Salesforce Lightning

Here, are the steps to extract Year from Date using the Advance Formula in Salesforce Lightning.

Step 1: Navigate to Salesforce Setup, by clicking on the Setup icon on the upper right side of the page.

Step 2: On the left side of the menu, click on Object Manager.

Extract Year from Date using Advance Formula
Extract Year from Date using Advance Formula

Step 3: Search for the object to which we want to extract the year from the date field. Here, I select the Products object from the list of objects.

Extract Year from Date using Advance Formula Example
Extract Year from Date using Advance Formula Example

Step 4: Click on Fields & Relationships.

Step 5: Then, click on New.

Extract Year from Date using Salesforce
Extract Year from Date using Salesforce

Step 6: Choose the Formula as the field type.

Step 7: To continue, click Next.

Extract Year from Date using Salesforce Advance Formula
Extract Year from Date using Salesforce Advance Formula

Step 8: Enter a Field Label for the formula, and the Field Name will be automatically populated. Here, I enter Field Label as the Expiry Year.

Step 9: Choose Text as the Formula Return Type because by default the YEAR function displays the result in number system format i.e separate number places with commas. Then click Next.

Extract Year from Date in Salesforce
Extract Year from Date in Salesforce

Step 10: Enter the Extract Year from Date formula in the Advance Formula editor. Here, is the formula:

TEXT(YEAR(Product_Expiry_Date__c))
  • In this formula, we fetch out the year from the date field called “Product_Expiry_Date__c” using the YEAR Salesforce function. But by default, the YEAR function returns the result in a number.
  • To get the result in the text format, we will use the TEXT function with the YEAR function.

Step 11: Click Check Syntax to make sure the formula is correct.

Step 12: We can add the Description and Help Text as options, and we can also state how you want to handle the blank field.

Step 13: After that, click Next.

How to extract Year from Date in Salesforce Lightning
Extract Year from Date using YEAR Formula

Step 14: Select the appropriate field Level Security and to make it visible to everyone, here we select the Visible checkbox.

Step 15: Select Next.

How to extract Year from Date in Salesforce Lightning Example
Year from Date in Salesforce Lightning Example

Step 16: Choose the Page Layout Name, for whom we want to add the formula field.

Step 17: To save the formula field, click Save.

Extract Year from Date in Salesforce Lightning
Extract Year from Date in Salesforce Lightning

We can use the formula field once we’ve created it. Let’s look at an example:

  • Create a new product using the Product Expiry Date value by opening the Products object and saving it.
  • After that, click on the Details section, and here the Expiry Year field will appear with the extracted year from the date value.
Extract Year from Date in Salesforce Lightning Example
Extract Year from Date in Salesforce Lightning Example

As a result, we now know how to use Salesforce Lightning’s advanced formula to extract the Year from the Date field. Next, we’ll look at how to use Salesforce Classic’s advance formula to extract the Year from the Date field.

Read Add Days to Date in Salesforce Formula

How to extract Year from Date in Salesforce Classic

Here, are the steps to extract Year from Date using the Advance Formula in Salesforce Classic.

Step 1: From the Salesforce Lightning to open your Salesforce Classic edition. Click on Avtar and click Switch to Salesforce Classic.

How to extract Year from Date in Salesforce Classic
Extract Year from Date in Salesforce Classic

Step 2: Click on the Setup option.

How to extract Year from Date in Salesforce Classic Example
Extract Year from Date in Salesforce Classic Example

Step 3: Scroll down to the Build section. Then under Customize, select the object for whom we want to extract the Year from the Date. Here, I choose the Accounts from the object list.

Step 4: Click on the dropdown menu and select Fields.

Extract Year from Date in Salesforce Classic
Extract Year from Date in Salesforce Classic

Step 5: As you scroll down the page, click on the New button under Custom Fields & Relationships.

Extract Year from Date in Salesforce Classic Example
Extract Year from Date in Salesforce Classic Example

Step 6: Select the Formula as the field type.

Step 7: Click Next to proceed.

Extract Year from Date using Salesforce Classic
Extract Year from Date using Salesforce Classic Advance Formula

Step 8: Enter a Field Label for the formula, and the Field Name will be automatically populated. Here, I enter Field Label as the Signed Year.

Step 9: Choose Number as the Formula Return Type because the YEAR function displays the output by default in number system format, which separates number places with commas, then click Next.

Extract Year from Date using Advance Formula in Salesforce Classic
Extract Year from Date using Advance Formula in Salesforce Classic

Step 10: The Advance Formula editor extracts the Year from the Date formula. The formula is as follows:

YEAR(CompanySigned)
  • In this formula, we use the YEAR Salesforce function to retrieve the year from the date column “CompanySigned”. However, the YEAR function by default returns the result as a number.

Step 11: To verify that the formula is valid, click Check Syntax.

Step 12: We can specify how you want to handle the empty field and include the Description and Help Text optionally.

Step 13: Then, click Next.

Extract Year from Date using Advance Formula in Salesforce Classic Example
Advance Formula to Extract Year from Date

Step 14: Choose the appropriate Field’s Level Security, and then check the box Visible to make it visible to all.

Step 15: Click Next.

Extract Year from Date using Salesforce Classic Advance Formula
Extract Year from Date using Salesforce Classic Advance Formula

Step 16: Choose the Page Layout Name for which the formula field is to be added.

Step 17: Click Save to save the formula field.

Salesforce Classic Extract Year from Date
Salesforce Classic Extract Year from Date

Once we’ve defined the formula field, we may use it. Let’s explore an example:

  • Create a new Contract with the ContractSigned field value by opening the Contracts object and saving it.
  • After that, click on the Details section, and here the Company Signed Year field will appear with the extracted year date value from the date value.
Salesforce Classic Example Extract Year from Date
Salesforce Classic Example Extract Year from Date

In a conclusion, we now understand how to extract the Year from Date using Salesforce Classic’s advanced formula.

Also, Read:

Conclusion

In conclusion, we have learned the advance salesforce formula to extract Year from Date.

Moreover, we have learned that both Salesforce Classic and Salesforce Lightning provide a simple procedure to Extract Year from the Salesforce Date field.

In addition to this, the following are the topics that we have discussed:

  • Extract Year from Date using Advance Formula
  • How to extract Year from Date in Salesforce Lightning
  • How to extract Year from Date in Salesforce Classic