Sp-dev-docs: ValidateUpdateItem Date Time FieldValue formats

Created on 18 Nov 2019  Â·  5Comments  Â·  Source: SharePoint/sp-dev-docs

I'd like to request a bit more information on the AddValidateUpdateItemUsingPath/ValidateUpdateListItem REST endpoints in regards to Date/Time fields.

I know that supplying an ISO formatted string to the FieldValue property in the FormValues object will result in an error. It seems you need to know the format that the endpoint will accept.

Depending on your locale settings in your SPWeb object, the format may be "DD/MM/YYYY hh:mm" or "MM/DD/YYYY hh:mm AM/PM" and possibly other variations (e.g., the date separator might need to be '-').

Given the information supplied by ClientFormSchema for a date time field, I don't know how to format the value in a reliable generic way that the API will always accept. Just for reference, here's the ClientFormSchema for a date/time field

CalendarType: 1
ClientValidationFormula: null
ClientValidationMessage: null
DefaultValue: "[today]"
DefaultValueFormatted: "18/11/2019 16:0"
DefaultValueTyped: "/Date(1574121600000)/"
Description: ""
Direction: "none"
DisplayFormat: 1
FieldType: "DateTime"
FirstDayOfWeek: 1
FirstWeekOfYear: 2
Hidden: false
HijriAdjustment: 0
HoursMode24: true
HoursOptions: Array(24)
0: "00:"
1: "01:"
2: "02:"
3: "03:"
4: "04:"
5: "05:"
6: "06:"
7: "07:"
8: "08:"
9: "09:"
10: "10:"
11: "11:"
12: "12:"
13: "13:"
14: "14:"
15: "15:"
16: "16:"
17: "17:"
18: "18:"
19: "19:"
20: "20:"
21: "21:"
22: "22:"
23: "23:"
length: 24
__proto__: Array(0)
IMEMode: null
Id: "516b6de7-5ee4-4c71-af4b-020a4a679228"
InternalName: "DateStarted"
IsAutoHyperLink: false
LanguageId: "1033"
LocaleId: "2057"
MaxJDay: 2666269
MinJDay: 109207
Name: "DateStarted"
ReadOnlyField: false
Required: false
ShowWeekNumber: false
StaticName: "DateStarted"
TimeSeparator: ":"
TimeZoneDifference: "-00:00:00.0003475"
Title: "DateStarted"
Type: "DateTime"
WorkWeek: "0111110"

So I get a TimeSeparator property but that's about it in terms of what format the aforementioned APIs will accept. I also get a LocaleId which could be used in toLocaleString() on a Date object but MDN advises against relying on the output of that method.
Furthermore, SharePoint doesn't like the comma this method might place in between the date and time.
The error I get with my SPWeb locale configuration is as follows

Enter a date and time like this: 23/02/2012 14:25

And if I change the locale information on my SPWeb object

Enter a date and time like this: 2/23/2012 2:25 PM

I know that the Modern UI uses these APIs for creating/updating items so how are the default forms able to work out what date format to put in FieldValue for a date time field type?


Document Details

⚠ Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.

csorest docs-comment question

All 5 comments

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

It will be very helpful if ISO formatted date times were supported.
@semopz I think "yyyy-mm-dd hh:mm:ss" fotmat always works.
Also, note that the site timezone offset will be applied, so when you use ValidateUpdateListItem with FieldValue=2020-03-11 18:00:00, that is NOT the date that will be saved in SharePoint (unless your site is configured in UTC 0).

"yyyy-MM-dd hh:mm:ss"

It will be very helpful if ISO formatted date times were supported.

If you want to easily get the supported value from a Date:

let dateStringValue = new Date().toISOString().substr(0, 19).replace('T', ' ');

Don't forget to take timezone into account:

let dateStringValue = new Date(new Date().getTime() - new Date().getTimezoneOffset()*60*1000).toISOString().substr(0,19).replace('T', ' ')

Was this page helpful?
0 / 5 - 0 ratings