Calculation year formula?

09-07-2022 07:43 AM
New Contributor III

I am posting for a coworker. He is using Connect version 3.13.

He has a field that is calculated with the formula format-date(today(), '%Y')-${repeat_no}

In an older version it works fine. Example below.

Version 2


He made a new version and did not change this field but now he gets December 1969.

What happened?

version 3



0 Kudos
1 Reply
Occasional Contributor II

The problem has occurred because he has changed the question type. He may not have changed the calculation field, but in version 2 the answer is clearly being returned as an integer/text, while in version 3 it is being returned as a date. 

If he changes the [type] field for ${Fert year} back to "integer" it will work just fine.

A [date] type question will always return the full Y_M_D string. Even if you ask for the answer as a YYYY string in the calculation, using the [date] question type will just add back the other fields as 0 or 1 values. So 2022-09-08 gets reduced to a string off 2022, then converted back to 2022-01-01.

So what your friend has done is asked the app to convert the year to string using  format-date, and then asked it format that string as a Y_M_D date by using the [date] type. He has then asked it to subtract the integer from the date 2022-01-01.

Of course the result of that is nonsense. So the app can't return a valid date value, and instead then returns the default epoch date- 31-12-1969