Simplest solution is to use toLocaleDateString
like this:
{
"rowFormatter": {
"elmType": "span",
"txtContent": "=toLocaleDateString([$Date])",
"style": {
"display": "=if([$Date] == '', 'none', 'block')",
"padding-left": "3px"
}
}
}
When the user is in the US, for instance, the above format will look similar to 8/26/2020
If you need more control you could also use the getDate
, getMonth
, and/or the getYear
operators. For instance, to just show the shortened month and day you could do this:
{
"rowFormatter": {
"elmType": "span",
"txtContent": "=if(getMonth([$Date])==0,'Jan',if(getMonth([$Date])==1,'Feb',if(getMonth([$Date])==2,'Mar',if(getMonth([$Date])==3,'Apr',if(getMonth([$Date])==4,'May',if(getMonth([$Date])==5,'Jun',if(getMonth([$Date])==6,'Jul',if(getMonth([$Date])==7,'Aug',if(getMonth([$Date])==8,'Sept',if(getMonth([$Date])==9,'Oct',if(getMonth([$Date])==10,'Nov','Dec'))))))))))) + ' ' + getDate([$Date])",
"style": {
"display": "=if([$Date] == '', 'none', 'block')",
"padding-left": "3px"
}
}
}
This will result in values like Aug 26 regardless of the user's location.
You can find more samples of using dates in formatting here: https://aka.ms/list-formatting