Expand my Community achievements bar.

Guidelines for the Responsible Use of Generative AI in the Experience Cloud Community.
SOLVED

Extract Year (only) from Date Field and Display in Text Field

Avatar

Level 9

I need to extract the year from a user entered date field and display the year in a text field. Can someone help me with the correct script to do this?

1 Accepted Solution

Avatar

Correct answer by
Level 10

Hi,

that's quite easy to realize with FormCalc.

In you date fields exit event add the following code:


textField1 = Num2Date( Date2Num($.formattedValue, "MM/DD/YYYY"), "YYYY")


Note: This sample assumes that your date field formats the date with "MM/DD/YYYY". You may have to change the pattern to make it work at your end.

View solution in original post

2 Replies

Avatar

Correct answer by
Level 10

Hi,

that's quite easy to realize with FormCalc.

In you date fields exit event add the following code:


textField1 = Num2Date( Date2Num($.formattedValue, "MM/DD/YYYY"), "YYYY")


Note: This sample assumes that your date field formats the date with "MM/DD/YYYY". You may have to change the pattern to make it work at your end.