0

I have the following code inside my remote event recevier, to assing a value for a Date Time field, as follow:-

public SPRemoteEventResult ProcessEvent(SPRemoteEventProperties properties)
        {
  using (ClientContext context = Helpers.GetAppOnlyContext(siteUrl))
            {
          if (properties.ItemEventProperties.AfterProperties["ProjectApproveDelay"] != null && properties.ItemEventProperties.AfterProperties["ProjectApproveDelay"].ToString().ToLower() == "yes" )
             {
               result.ChangedItemProperties.Add("ProjectEstimatedCompletionCurren0", DateTime.Now);         
             }

but this will return the following error:-

Invalid date/time value. A date/time field contains invalid data. Please check the value and try again.

although both the server hosing the remove event receiver + the site collection follow the UK time standard. and the DateTime.Now will be something as follow 27/01/2020 23:01:32

1
  • Im not sure, but try this code, DateTime.Now.ToString("yyyy-MM-ddTHH:mm:ssZ") Jan 27, 2020 at 11:59

1 Answer 1

1

In SharePoint, Date and Time Field takes date in ISO Format.

So, try converting date-time value in ISO format and then use it.

Try below solutions:

  1. Converting to ISO Format:

    DateTime.Now.ToString("yyyy-MM-ddTHH:mm:ssZ");

    Given a DateTime object, how do I get an ISO 8601 date in string format?

  2. Try using Invariant Date Format:

    DateTime.Now.ToString(DateTimeFormatInfo.InvariantInfo);

    SharePoint: Assigning values to DateTime fields.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.