JSON to display date as mmm-yyyy is MS Lists without using a calculated column.

Carter, Miriam 21 Reputation points

Hello, can you help me write JSON to display date as mmm-yyyy is MS Lists without using a calculated column?
I'm pretty sure this is possible but I'm a novice to both MS Lists and JSON and I haven't been able to make it work.

I need a date column to display as mmm-yyyy, for example 'Jan-2021.' I know its very easy to create a calculated column from another date column and display in this manner using a TEXT formula, however, I don't want to confuse my data-entry users by having one date column where they pick a date to enter their monthly results and then see that month displayed in a separate column. I know they will just try to click into the Month display and enter the month there instead of using the separate date picker column.

I found code that's close to what I need, but it just results in displaying the JSON code itself, not the actual results. I'm sure I'm doing something wrong but not sure what.

"$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json",
"elmType": "span",
"txtContent": "=if(getMonth([$Month-Year])==0,'Jan',if(getMonth([$Month-Year])==1,'Feb',if(getMonth([$Month-Year])==2,'Mar',if(getMonth([$Month-Year])==3,'Apr',if(getMonth([$Month-Year])==4,'May',if(getMonth([$Month-Year])==5,'Jun',if(getMonth([$Month-Year])==6,'Jul',if(getMonth([$Month-Year])==7,'Aug',if(getMonth([$Month-Year])==8,'Sept',if(getMonth([$Month-Year])==9,'Oct',if(getMonth([$Month-Year])==10,'Nov','Dec'))))))))))) + '-' + getYear([$Month-Year])"

A group of Microsoft Products and technologies used for sharing and managing content, knowledge, and applications.
6,519 questions
No comments
{count} votes

Accepted answer
  1. Yi Lu_MSFT 17,171 Reputation points

    Hi @Carter, Miriam
    You could try the following code:

           "$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json",  
           "elmType": "span",  
           "txtContent": "=if(getMonth(@currentField)==0,'Jan',if(getMonth(@currentField)==1,'Feb',if(getMonth(@currentField)==2,'Mar',if(getMonth(@currentField)==3,'Apr',if(getMonth(@currentField)==4,'May',if(getMonth(@currentField)==5,'Jun',if(getMonth(@currentField)==6,'Jul',if(getMonth(@currentField)==7,'Aug',if(getMonth(@currentField)==8,'Sept',if(getMonth(@currentField)==9,'Oct',if(getMonth(@currentField)==10,'Nov','Dec'))))))))))) + '-' + getYear(@currentField)"  

    As a result, you will get the format:


    If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

0 additional answers

Sort by: Most helpful