Set value of datetime field to null

Tag: sharepoint Author: liuyuanxuna Date: 2009-07-14

So, I´ve got an issue that someone might have solved (or so I hope). I have a datetime field that I use in a contenttype (on a listtemplate) that has its own editform.

Here´s a walkthrough of what happens:

  1. Adding a value to the datetime column and saving the updated value shows up (as expected).
  2. Updating the datetime column and adding null (emptying out the value) via the editform. The value isn´t updated but instead showing the old value.

I did some experimenting with this and I came to the conclusion that if I add an eventreceiver and try to update the value there it doesn´t even enter the eventreceiver as a blank string (I had an idea that the value is as a blank string and sharepoint can´t parse that to a null datetime) which leads me to think that there´s an issue with the fieldcontrol that causes this. I also found this article on MSDN which seems to be around the same issue. And also, the datetime field in the contenttype isn´t required.

Any ideas or suggestions?


Apparently this only happens when I use a custom editform. When I use one of built in listtemplates this works like a charm.

Other Answer1

I've had similar issues with this in the past. It is indeed a known bug. One work around is to set the field to the min or max value of the type and check for this value wherever needed and do the appropriate conversions. Depending on your setup and use, you could create a trigger to convert min/max values to null and thus minimize the code required to handle such a work around.

Other Answer2

After some deep investiongation I have found that the root of this problem is related to the fact that I was using XML node propagation between the columns in the list and the actual xml file. I had prevoiusly been struggling with this regarding stardard text fields and thought that I had taken care of the issue..apparently not. DateTime fields apparently will not get sent to the eventreceiver afterproperties if it is null as thus my code will not pick it up as a null value. I had to take case of that and add them to afterproperties if I can´t find them in afterproperties. I will make a blogpost series about these issues and post the links to this post shortly.


I have now completed a blogpost about how I solved this issue. Feel free to check it out: