0

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?

SuperDOS
  • 301
  • 1
  • 3
  • 16

2 Answers2

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")

thebernardlim
  • 755
  • 2
  • 10
  • 23
  • Thanks, had some issues because of regional settings but I got it working now with a calculated column :) – SuperDOS Apr 27 '23 at 08:19
0

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

Ganesh Sanap
  • 1,386
  • 1
  • 8
  • 18