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

ValidateUpdateItem Date Time FieldValue formats

Open semopz opened this issue 7 years ago • 9 comments

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.

semopz avatar Nov 18 '19 15:11 semopz

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

msft-github-bot avatar Nov 18 '19 15:11 msft-github-bot

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

Rafaelki avatar Mar 11 '20 17:03 Rafaelki

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

johnnliu avatar Jun 23 '20 18:06 johnnliu

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

justin0522 avatar Aug 26 '20 07:08 justin0522

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', ' ')

MathieuMarchant avatar Aug 28 '20 11:08 MathieuMarchant

Thanks @EagleWizard28, that worked for me irrespective of Regional settings.

TjWheeler avatar Jan 28 '21 10:01 TjWheeler

According to the SharePoint Online OData CSDL, the actions AddValidateUpdateItem and AddValidateUpdateItemUsingPath both accept a datesInUTC parameter where, judging from the name, you can force dates to be applied in UTC format irrespective of Regional settings

fredrikhr avatar Jun 08 '21 09:06 fredrikhr

datesInUTC parameter seems to be available in ValidateUpdateListItem. It also seems like that allows submitting dates in ISO format.

gabbsmo avatar May 24 '22 11:05 gabbsmo

Thank you for taking the time to file an issue. We periodically archive older or inactive issues as part of our issue management process, which automatically closes them once they are archived.

If you’d like to understand more about why and how we handle archived (closed) issues, please see Our approach to closed issues.

We appreciate your contribution and if this is still an active issue with the latest SPFx versions, please do resubmit the details. We needed to perform a cleanup, so that we can start with a clean table with a new process. We apologize for the inconvenience this might cause.

github-actions[bot] avatar May 02 '25 14:05 github-actions[bot]