In my list I have a column with dates. I want a field in this column to turn yellow when the date is more than X years ago. Where X is a number in another column.
For example: Date in field A2 is "1-1-2024". Number in field B2 is "2" (meaning a check is needed every two years). Because 1-1-2024 is less than two years ago, the field remains white. Date in field A3 is "1-1-2024". Number in field B3 is "1". Because 1-1-2024 is more than one year ago, the field turns yellow.
I'm fairly new to formatting in lists but have managed to get some things working. After a deep dive in online JSON tips I tried adding a multiplication to a working simpler JSON. It does something, but not what I am trying to do.
Is what I want possible? Do I need an additional column with a calculated number to make it work?
The code I tried:
"$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json", "elmType": "div", "txtContent": "= @currentField", "attributes": { "class": "=if (@currentField + 31536000000 * @currentItem.testnummer <= @now,'ms-bgColor-yellow', '')" +++ EDIT 3 +++ Both samples in the answer of @matiur-rahman eventually worked! They didn't at first, but a week later suddenly the background-colour was there.
+++ EDIT 1 +++ A working JSON, but simpler, does change the background colour. This misses the multiplication with the numbers in the other column.
{ "$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json", "elmType": "div", "txtContent": "= @currentField", "attributes": { "class": "=if (@currentField + 31536000000 <= @now,'ms-bgColor-yellow', '')" } }
+++ EDIT 2 +++ Two users kindly reacted to my initial question. I tried their suggestions. @Rothrock suggested suggested changing the direction of "<" and next the position of the arithmic. Both do work in the JSON that worked, but eacht time I insert the multiplication it doesn't. The fields remain yellow and the text disappears for some reason.
@matiur-rahman suggested a different approach. I tried that first in my existing List but there only the first test sample step worked, the sample that should do what I wanted did not. I made a new List and used the data, column names and samples that matiur gave me. The results were the same, as you can see here:

It should give the same results as @matiur-rahman's answer. The samples:
{ "$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json", "elmType": "div", "txtContent": "@currentField", "attributes": { "class": "=if(@currentField<Date(toLocaleDateString(Date(toString(getMonth(@now)) + '/'+ toString(getDate(@now))+ '/' + toString(getYear(@now)-[$NumberColumn])))), 'ms-bgColor-yellow', '')" } } { "$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json", "elmType": "div", "txtContent": "=toLocaleDateString(Date(toString(getMonth(@now)) + '/'+ toString(getDate(@now))+ '/' + toString(getYear(@now)-[$NumberColumn])))", "style": { "color": "green", "font-size": "1em", "justify-content": "center" } } 