Forum Discussion
JSON Form Header Date Calculation
ianthegeordie1892 Try using JSON like below in list form header layout:
{
"elmType": "div",
"txtContent": "=if(Number([$TargetDateForTrial]) == 0, '', if(Date([$TargetDateForTrial]) <= Date(addDays(@now,90)),'OK','Please select date within 90 days.'))"
}
Where [$TargetDateForTrial] is an internal name of your date column in SharePoint list in this format: [$InternalNameOfColumn]. You can get the internal name of your SharePoint list columns by following this article: How to find the Internal name of columns in SharePoint Online?
Here, I have used Number([$TargetDateForTrial]) == 0 to check if SharePoint date column is blank or not. You can find other ways to check if SharePoint date & time column is empty or not at: SharePoint JSON formatting: Check if date & time column is blank/empty
Please click Mark as Best Response & Like if my post helped you to solve your issue. This will help others to find the correct solution easily. It also closes the item. If the post was useful in other ways, please consider giving it Like.
- ganeshsanapFeb 07, 2024MVP
ianthegeordie1892 What is the exact issue when you say "it still doesn't seem to work"? Can you add the screenshots of list form if possible?
Is it not showing the text correctly or are you getting any error message or anything else?
Are you using correct internal name of the date field as suggested above?
And yes, I have tested this on list form and it works for me. Here is the output:
Please click Mark as Best Response & Like if my post helped you to solve your issue. This will help others to find the correct solution easily. It also closes the item. If the post was useful in other ways, please consider giving it Like.
- ianthegeordie1892Feb 07, 2024Copper Contributor
ganeshsanap Hi the initial selection of the field works but if I change it to a value beyond 90 days it keeps the same message. Yes i use internal names with all my JSON code etc
- ganeshsanapFeb 07, 2024MVP
ianthegeordie1892 Are you using dd/mm/yyyy format for your dates (site regional settings)?
Can you try using the toLocaleDateString() function instead of Date()?
{ "elmType": "div", "txtContent": "=if(Number([$TargetDateForTrial]) == 0, '', if(toLocaleDateString([$TargetDateForTrial]) <= toLocaleDateString(addDays(@now,90)),'OK','Please select date within 90 days.'))" }
Please click Mark as Best Response & Like if my post helped you to solve your issue. This will help others to find the correct solution easily. It also closes the item. If the post was useful in other ways, please consider giving it Like.