Skip to content

ValidateUpdateItem Date Time FieldValue formats #4917

@semopz

Description

@semopz

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:csom/rest/apiCategory: SharePoint Client Side Object Model SDK / REST APIarea:docs-commentCategory: Comment left on bottom of a docs page here: https://docs.microsoft.com/sharepoint/devtype:archive-old-issueIssues which are closed as tool old for active worktype:questionQuestion... if answered, will be tagged as such.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions