Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

We tried to use DateTime.MaxValue to set empty value for DateTimeField and it works quite nice on our test environment, but we get following exception on some production farms.

Exception: Ticks must be between DateTime.MinValue.Ticks and DateTime.MaxValue.Ticks. Parameter name: ticks, Stack Trace: at System.DateTime..ctor(Int64 ticks) at Microsoft.SharePoint.SPTimeZone.ConvertToUTC(DateTime date, UInt16 tzid) at Microsoft.SharePoint.WebControls.DateTimeField.set_Value(Object value)

Can anyone suggest how we can workaround this?

share|improve this question
add comment

1 Answer

try handling it with IsDateEmpty property, while saving it. for e.g.

if (!yourDatecontrol.IsDateEmpty)
{
    item["Date"] = yourDatecontrol.SelectedDate;
}
else
{
    item["Date"] = null;
}

Call ClearSelection method for empty value.

yourDatecontrol.ClearSelection();
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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