locked
Is it possible to clear the value on a SPFieldDateTime? RRS feed

  • Question

  • Hello everyone,

    This may be straightforward but I can't seem to clear the value of a SPFieldDate programmatically. The field is not required, the standard value is set to empty and other items in the list have an empty value. I have tried setting the value to "" and null, but nothing worked. It seems like SharePoint is trying to parse whatever value I assign as a DateTime before setting the value. Also there is no FieldValue class for dates like the "TaxonomyFieldValue" for taxonomy fields so how do you clear the field value once it has been set?


    • Edited by Stig P. Rasmussen Sunday, September 6, 2015 8:22 AM added additional info
    Friday, September 4, 2015 11:09 AM

Answers

  • I found a way to do it :-)

    I changed the call I made from this:

    myListItem[myInternalFieldName] = "";
    to this:

    var myField = myListItem.Fields.GetFieldByInternalName(myInternalFieldName);

    myListItem[myFieldInternalName] = myField.ParseValue(myListItem, "");


    Sunday, September 6, 2015 9:17 AM