SOLVED

JSON Sharepoint Date Validation

Copper Contributor

Hi, I'm new on JSON Script.
I've problem for JSON Validate Date on Sharepoint online.

I just write on sharepoint 365 online

 

{ "$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json", "elmType": "div", "txtContent": "=if(@now>=[$StartDate],if(@now<=[$EndDate],'active','non active'),'non active')" }

 

My problem the result always non active when it saved.

I need status will be "active" if date range on current month and will be change automatically to "Non Active" if out of current month

I hope my pic can tell about my problem

Thanks everyone

8 Replies
best response confirmed by lucasignatius (Copper Contributor)
Solution

@lucasignatius 

 

Can you please add more details about your requirement & conditions to check?

 

Do you want to show the column value as "Active" when current (today's) date is in between Start date and End Date? Or if both the Start date and End date are in current month?


Please click Mark as Best Response 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.

 

@ganeshsanap sorry for my question is have a little missing.

I mean is "Active" when current (today's) date is in between Start date and End Date.

Thanks for your help

 

 

@lucasignatius 

Try using below JSON code. It should work for you:

 

{
    "$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json",
    "elmType": "div",
    "txtContent": "=if(@now >= [$StartDate] && @now <= [$EndDate], 'Active', 'Not Active')"
}

 

Microsoft documentationUse column formatting to customize SharePoint 


Please click Mark as Best Response 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.

 

@ganeshsanap 

Hi, I just tried but it still not working status still "not active"

 

@lucasignatius 

 

What is the internal name of Start date and End date columns?

 

In JSON formatting, you need to use internal name of your columns to refer their value in JSON code. Check below documentation to find out the internal names of start date and end date. and use those in place of [$StartDate] and [$EndDate].

 

Follow this article to get the internal name your SharePoint column: Find the internal name of SharePoint column 

 

Here is the output of the same code in my SharePoint list:

Json formatting output.PNG

Microsoft documentation[$FieldName] 


 

@ganeshsanap your are the best :cool:

Thanks for your help, anyway do you know how to give color (example, active will be green, non active will be red).

JSON DONE.PNG

@lucasignatius 

 

Use below code for changing colors:

 

 

{
    "$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json",
    "elmType": "div",
    "txtContent": "=if(@now >= [$StartDate] && @now <= [$EndDate], 'Active', 'Non Active')",
    "style": {
        "color": "=if(@now >= [$StartDate] && @now <= [$EndDate], 'green', 'red')",
        "font-weight": "bold"
    }
}

 

 

For more information related to styling refer: Use column formatting to customize SharePoint 


If my posts was useful to you, please consider giving it Likes.

 

@ganeshsanap yeah.. it work :cool:

Thanks yoo..

And I'll closed this case

1 best response

Accepted Solutions
best response confirmed by lucasignatius (Copper Contributor)
Solution

@lucasignatius 

 

Can you please add more details about your requirement & conditions to check?

 

Do you want to show the column value as "Active" when current (today's) date is in between Start date and End Date? Or if both the Start date and End date are in current month?


Please click Mark as Best Response 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.

 

View solution in original post