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.
Hi, This works perfectly in my site, however I want to include the day also so it appears as 01-Feb-2021. I've tried editing this numerous ways and just can't get it to work. What am i doing wrong?
okay I've not done any Java stuff before but managed to work out something that works for getting the day.
{
"$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json",
"elmType": "span",
"txtContent": "=getDate(@currentField) + '-' +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)"
}
While the code above works it shows single dates without the prefixing 0
e.g. 1-Jan-2022 instead of 01-Jan-2022
If (like me) you need GMP formatted dates then the code below will do it (there's probably a better way to do it than this but this is what I managed to come up with)
{
"$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json",
"elmType": "span",
"txtContent": "=if(getDate(@currentField)==1,'01',if(getDate(@currentField)==2,'02',if(getDate(@currentField)==3,'03',if(getDate(@currentField)==4,'04',if(getDate(@currentField)==5,'05',if(getDate(@currentField)==6,'06',if(getDate(@currentField)==7,'07',if(getDate(@currentField)==8,'08',if(getDate(@currentField)==9,'09',getDate(@currentField))))))))))+ '-' +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)"
}
Hope this helps
Tried to edit my response but it wouldn't let me. :( had some more issues
If (like me) you need GMP formatted dates then the code below will produce dates in format ddmmmyyyy (no dashes) & replaces blanks fields with N/A
(remove N/A from the code if you want blank fields)
{
"$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json",
"elmType": "span",
"txtContent": "=if(getDate(@currentField)==1,'01',if(getDate(@currentField)==2,'02',if(getDate(@currentField)==3,'03',if(getDate(@currentField)==4,'04',if(getDate(@currentField)==5,'05',if(getDate(@currentField)==6,'06',if(getDate(@currentField)==7,'07',if(getDate(@currentField)==8,'08',if(getDate(@currentField)==9,'09',getDate(@currentField)))))))))) + ''+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',if(getMonth(@currentField)==11,'Dec','N/A')))))))))))) + '' + getYear(@currentField)"
}
Hope this helps
Tried to edit my previous response but it wouldn't let me. :( had some more issues with the code found it
My QA Dept. wanted dates in format ddmmmyyyy (no dashes) & to replace blanks fields with N/A (you can remove N/A from the code below if you want blank fields)
{
"$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json",
"elmType": "span",
"txtContent": "=if(getDate(@currentField)==1,'01',if(getDate(@currentField)==2,'02',if(getDate(@currentField)==3,'03',if(getDate(@currentField)==4,'04',if(getDate(@currentField)==5,'05',if(getDate(@currentField)==6,'06',if(getDate(@currentField)==7,'07',if(getDate(@currentField)==8,'08',if(getDate(@currentField)==9,'09',getDate(@currentField)))))))))) + ''+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',if(getMonth(@currentField)==11,'Dec','N/A')))))))))))) + '' + getYear(@currentField)"
}
This works perfectly for me. Many thanks
Sign in to comment