Back to column formats
Column formattingSharePoint Online

Days Counter

This sample shows how many days are left until a date or how many days have passed since a date, right inside a SharePoint list column. Color-coded for quick scanning.

Days Counter formatting preview
Sample preview · View original image

Copy. Apply. Make it yours.

Get this format

1 definition

Review the requirements below, then paste this JSON into the matching formatting panel. Show me where.

Use your list's internal column names and replace any tenant-specific URLs or flow IDs. Formatting is presentation, not a way to secure data.

Column formatting
Download JSON
{
  "$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json",
  "elmType": "div",
  "style": {
    "display": "=if(@currentField, 'flex', 'none')",
    "flex-direction": "column",
    "align-items": "flex-start",
    "justify-content": "flex-start",
    "padding": "10px",
    "padding-bottom": "0px",
    "font-size": "12px",
    "color": "#323130"
  },
  "children": [
    {
      "elmType": "div",
      "style": {
        "display": "flex",
        "align-items": "center",
        "gap": "4px"
      },
      "children": [
        {
          "elmType": "span",
          "txtContent": "=if(floor((Date(@currentField) + 46800000) / 86400000) == floor((@now + 46800000) / 86400000), '0d', if(floor((Date(@currentField) + 46800000) / 86400000) > floor((@now + 46800000) / 86400000), toString(floor((Date(@currentField) + 46800000) / 86400000 - floor((@now + 46800000) / 86400000))) + 'd', '-' + toString(floor((@now + 46800000) / 86400000 - (Date(@currentField) + 46800000) / 86400000)) + 'd'))",
          "style": {
            "color": "#666",
            "font-size": "10px",
            "padding-right": "1px"
          }
        },
        {
          "elmType": "span",
          "attributes": {
            "iconName": "=if(floor((Date(@currentField) + 46800000) / 86400000) > floor((@now + 46800000) / 86400000), 'SortUp', if(floor((Date(@currentField) + 46800000) / 86400000) < floor((@now + 46800000) / 86400000), 'SortDown', 'CheckMark'))"
          },
          "style": {
            "font-size": "10px",
            "color": "=if(floor((Date(@currentField) + 46800000) / 86400000) > floor((@now + 46800000) / 86400000), '#107c10', if(floor((Date(@currentField) + 46800000) / 86400000) < floor((@now + 46800000) / 86400000), '#a4262c', '#666'))"
          }
        }
      ]
    },
    {
      "elmType": "div",
      "style": {
        "display": "flex",
        "align-items": "center",
        "gap": "4px",
        "margin-top": "2px"
      },
      "children": [
        {
          "elmType": "span",
          "attributes": {
            "iconName": "Calendar"
          },
          "style": {
            "font-size": "12px",
            "padding-right": "5px"
          }
        },
        {
          "elmType": "span",
          "txtContent": "@currentField",
          "style": {
            "font-weight": "500"
          }
        }
      ]
    }
  ]
}

From the contributor

How to use this sample

Summary

This sample shows how many days are left until a date or how many days have passed since a date, right inside a SharePoint list column. Color-coded for quick scanning.

screenshot of the sample

View requirements

This format can be applied to a Date column.

Sample

Solution Author(s)
date-day-counter.json Tanel Vahk

Version history

Version Date Comments
1.0 August 19, 2025 Initial release

Disclaimer

THIS CODE IS PROVIDED AS IS WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT.