1

I'm trying to insert a DateTime value in a field which is configured as Date Only in Sharepoint list.

I've tried so far:

item["End_x0020_Date"] = Convert.ToDateTime("11/29/2017");

item["End_x0020_Date"] = DateTime.Now;

I haven't received any error but the value for dates is not stored in the list. All the other fields are filled correctly. You can see the blanks below the dates I added from Sharepoint. Any help would be appreciated.

Code:

 var web = context.Web;
 List list = web.Lists.GetByTitle(listName);

 ListItemCreationInformation itemCreateInfo = new ListItemCreationInformation();

 ListItem item = list.AddItem(itemCreateInfo);

 item["DepartmentName"] = "IT - Networking";
 item["StartDate"] = DateTime.Now.ToString();
 item["EndDate"] = Convert.ToDateTime("12/10/2017");

enter image description here

  • can you try using item["StartDate"] = DateTime.UtcNow and check ? – Gautam Sheth Nov 30 '17 at 6:54
0

Dates are stored in ISO format so try this:

item["EndDate"] = SPUtility.CreateISO8601DateTimeFromSystemDateTime(DateTime.Now());
| improve this answer | |
  • Thanks, How can I use that in CSOM? I couldn't find CreateISO8601DateTimeFromSystemDateTime – Carlos M Nov 30 '17 at 4:31
  • I use datetimeobject.toISOString() – Mike Nov 30 '17 at 14:39
0

For CSOM use below:

var startdate=new Date()
var enddate=new Date("12/10/2017")
item["StartDate"]= startdate
item["EndDate"]= enddate
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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