Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ValidateUpdateItem Date Time FieldValue formats #4917

Open
semopz opened this issue Nov 18, 2019 — with docs.microsoft.com · 8 comments
Open

ValidateUpdateItem Date Time FieldValue formats #4917

semopz opened this issue Nov 18, 2019 — with docs.microsoft.com · 8 comments
Labels
area:csom/rest/api Category: SharePoint Client Side Object Model SDK / REST API area:docs-comment Category: Comment left on bottom of a docs page here: https://docs.microsoft.com/sharepoint/dev type:question Question... if answered, will be tagged as such.

Comments

Copy link

semopz commented Nov 18, 2019

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.

@msft-github-bot
Copy link
Collaborator

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

@msft-github-bot msft-github-bot added the Needs: Triage 🔍 Awaiting categorization and initial review. label Nov 18, 2019
@andrewconnell andrewconnell added area:csom/rest/api Category: SharePoint Client Side Object Model SDK / REST API area:docs-comment Category: Comment left on bottom of a docs page here: https://docs.microsoft.com/sharepoint/dev type:question Question... if answered, will be tagged as such. and removed Needs: Triage 🔍 Awaiting categorization and initial review. labels Nov 19, 2019
@Rafaelki
Copy link

Rafaelki commented Mar 11, 2020

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

@johnnliu
Copy link
Contributor

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

@justin0522
Copy link

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

@MathieuMarchant
Copy link

MathieuMarchant commented Aug 28, 2020

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

@TjWheeler
Copy link

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

@fredrikhr
Copy link

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

@gabbsmo
Copy link

gabbsmo commented May 24, 2022

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:csom/rest/api Category: SharePoint Client Side Object Model SDK / REST API area:docs-comment Category: Comment left on bottom of a docs page here: https://docs.microsoft.com/sharepoint/dev type:question Question... if answered, will be tagged as such.
Projects
None yet
Development

No branches or pull requests

10 participants