sp-dev-docs icon indicating copy to clipboard operation
sp-dev-docs copied to clipboard

toLocaleDateString() not working in JSON list view formatting

Open JoeAyre opened this issue 6 years ago • 9 comments

It appears that the toLocaleDateString() function only works in JSON column formatting and not in JSON list view formatting. Is this expected?

JoeAyre avatar Aug 11 '20 05:08 JoeAyre

Thank you for reporting this issue. We will be triaging your incoming issue as soon as possible.

msft-github-bot avatar Aug 11 '20 05:08 msft-github-bot

I'm not seeing this issue currently:

Column Formatting: toLocaleDateString working in Column Formatting

View Formatting: toLocaleDateString working in View Formatting

Could you elaborate on your use case or provide a sample of your format? Thanks!

thechriskent avatar Aug 11 '20 14:08 thechriskent

Sure. I'm in Australia and the library I am working with is in a SharePoint site that has the following regional settings:

image

I am using list view formatting and have the following line to display the last modified person's name and when a document was last modified. The line of JSON is as follows:

"txtContent": "='Last modified by ' + [$Editor.title] + ', ' + toLocaleDateString([$Modified])",

The example document I am using was last modified on August 10, 2020 but using the JSON above, the display is as follows:

image

If I create a calculated column (called ModifiedDDMMYYYY) to format the 'Modified' column as text and use the following JSON:

"txtContent": "='Last modified by ' + [$Editor.title] + ', ' + [$ModifiedDDMMYYYY]",

....I get the following displayed:

image

My question is, why doesn't the toLocaleDateString() function have the desired effect i.e. displaying the date in DD/MM/YYYY format?

If you need any more details let me know. And thanks for being so quick to respond!

JoeAyre avatar Aug 12 '20 04:08 JoeAyre

Same issue here - toLocaleDateString() does not seem to adopt the correct date/time format set for the site/list

kikogerde avatar Aug 12 '20 11:08 kikogerde

@JoeAyre @kikogerde Thanks for reporting this.

toLocaleString, toLocaleTimeString and toLocaleDateString currently relies on the browser's locale settings, which may be different from Site/User locale settings. I will have a look at this.

I will recommend you to try .displayValue property for Date Fields, which will get the value based on the field settings.

shre-verse avatar Sep 10 '20 09:09 shre-verse

@JoeAyre @kikogerde This is now fixed, and shall be available on your tenants in upcoming updates.

shre-verse avatar Sep 16 '20 16:09 shre-verse

@JoeAyre @kikogerde @thechriskent I will recommend using .displayValue property in case you intend to maintain the default display text for Date fields. It's much easier to use and works with 'friendly format'.

shre-verse avatar Sep 16 '20 16:09 shre-verse

The fix is rolled out. Closing this.

shre-verse avatar Oct 21 '20 15:10 shre-verse

Issues that have been closed & had no follow-up activity for at least 7 days are automatically locked. Please refer to our wiki for more details, including how to remediate this action if you feel this was done prematurely or in error: Issue List: Our approach to locked issues

ghost avatar Oct 28 '20 18:10 ghost