skip to Main Content

I have a custom Format view for a list that I want to format a column called Date (date and time) so it’s displays current date and time without seconds.

{
            "elmType": "div",
            "inlineEditField": "[$Date]",
            "attributes": {
              "class": "sp-row-listPadding"
            },
            "style": {
              "margin-bottom": "10px",
              "margin-left": "10px",
              "font-size": "larger"
            },
            "txtContent": "=if(toLocaleDateString([$Date]) == '', toLocaleDateString([$Created]), toLocaleDateString([$Date])+' '+toLocaleTimeString([$Date]))"
          },

I’ve tried adding parameter to toLocalTime but doesn’t seem to be supported because it will type out the code instead of showing the formatted date.

toLocaleTimeString([$Date], {hour: '2-digit', minute:'2-digit'})

I also tried slice, substr, replace but doesn’t seem to be supported as well.

Is this possible in sharepoint?

2

Answers


  1. Can you create a calculated column for displaying date/time in your preferred format?

    If yes, create a calculated column with this formula
    =TEXT(Date,"dd/mm/yyyy HH:mm")

    Login or Signup to reply.
  2. If your date column is of type "Date and Time" (including time), use JSON txtContent like:

    "txtContent": "=if ([$Date.displayValue] == '', '–', [$Date.displayValue])"
    

    Where Date is internal name of your list column. You can get the exact internal name of your column by following this article: How to find the Internal name of columns in SharePoint Online?

    Output:

    enter image description here


    You can find other ways to check if date & time column is empty or not at: SharePoint JSON formatting: Check if date & time column is blank/empty

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search