SharePoint JSON formatting: Check if date & time column is blank/empty
SharePoint JSON formatting is a great way to customize how columns/fields are displayed in SharePoint list/library views. Many times you want to customize SharePoint list columns (like Status or Expiry of list item) based on other date & time columns in your list. While doing so, when you try to check if date & time column is blank/empty using below expression, it won’t work as expected:
"txtContent": "=if([$DueDate]) == '', '', [$DueDate])"
So, to check if date & time column is blank/empty using SharePoint JSON formatting, you have to use either of below workarounds:
Using Number() function
You can use Number(DateTimeColumn) == 0 to check if the date & time column is blank or not.
Example
{
"$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json",
"elmType": "div",
"txtContent": "=if(Number([$DueDate]) == 0, 'Blank Date', if([$DueDate] < @now, 'Expired', 'Active'))",
"attributes": {
"class": "=if(Number([$DueDate]) == 0, 'sp-field-severity--warning', if([$DueDate] < @now, 'sp-field-severity--blocked', 'sp-field-severity--good'))"
}
}
Where [$DueDate] is an internal name of your SharePoint date and time column.
Output

You can also find above JSON at list formatting samples on GitHub: Formatting a column when a date column is blank
Using toString() function
You can use toString(DateTimeColumn) == '' to check if the date & time column is blank or not.
Example
{
"$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json",
"elmType": "div",
"txtContent": "=if(toString([$DueDate]) == '', 'Blank Date', if([$DueDate] < @now, 'Expired', 'Active'))",
"attributes": {
"class": "=if(toString([$DueDate]) == '', 'sp-field-severity--warning', if([$DueDate] < @now, 'sp-field-severity--blocked', 'sp-field-severity--good'))"
}
}
Simplest way
You can also check if date & time column is blank/empty using below JSON:
{
"$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json",
"elmType": "div",
"txtContent": "=if(@currentField, @currentField, 'Blank Date')",
"attributes": {
"class": "=if(@currentField, 'sp-field-severity--good', 'sp-field-severity--warning')"
}
}
Output

Learn More
- Working with SharePoint Online/Microsoft List Comments using JSON Formatting
- SharePoint: Replace All Occurrences of Substring in a String using JSON Formatting
- SharePoint: Highlight selected list item rows using JSON formatting
- Download Image from SharePoint Image column using JSON formatting
- SharePoint Online: Download files from document library using JSON Formatting







