Back to column formats
Column formattingSharePoint Online

Date Update Format

Demonstrates updating a date value directly from the format.

date update format
Sample preview · View original animation

Copy. Apply. Make it yours.

Get this format

2 definitions

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",
  "children": [
    {
      "elmType": "div",
      "style": {
        "font-size": "14pt",
        "padding": "5px",
        "cursor": "pointer"
      },
      "attributes": {
        "iconName": "Calendar"
      },
      "customRowAction": {
        "action": "setValue",
        "actionInput": {
          "CustomDateYear": "@now"
        }
      }
    },
    {
      "elmType": "div",
      "attributes": {
        "iconName": "Add"
      },
      "style": {
        "font-size": "12pt",
        "padding": "5px",
        "cursor": "pointer"
      },
      "customRowAction": {
        "action": "setValue",
        "actionInput": {
          "CustomDateYear": "=addDays(Date([$CustomDateYear]),365)"
        }
      }
    },
    {
      "elmType": "div",
      "style": {
        "font-size": "12pt",
        "padding": "5px"
      },
      "txtContent": "=if(length([$CustomDateYear]) == 0,'(no date)',toLocaleDateString((Date([$CustomDateYear])))",
      "inlineEditField": "[$CustomDateYear]"
    },
    {
      "elmType": "div",
      "style": {
        "font-size": "12pt",
        "padding": "5px",
        "cursor": "pointer"
      },
      "attributes": {
        "iconName": "Remove"
      },
      "customRowAction": {
        "action": "setValue",
        "actionInput": {
          "CustomDateYear": "=addDays(Date([$CustomDateYear]),-365)"
        }
      }
    },
    {
      "elmType": "div",
      "style": {
        "cursor": "pointer"
      },
      "attributes": {
        "iconName": "ErrorBadge"
      },
      "customRowAction": {
        "action": "setValue",
        "actionInput": {
          "CustomDateYear": ""
        }
      }
    }
  ]
}

From the contributor

How to use this sample

Summary

This sample demonstrates updating a date value directly from the format. This includes setting the date to the current date/time, incremeting/decrementing the date by day (alternate format included to demonstrate incrementing/decrementing by year), and clearing the date.

screenshot of the sample

View requirements

  • The format expect the following fields:
Field Type
Title Single line of text
CustomDate Date and Time

Sample

Solution Author(s)
date-update-format.json André Lage
date-update-format-years.json André Lage

Version history

Version Date Comments
1.0 December 09, 2021 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.