My question is on validation of dates in SharePoint… If i have two date fields – start date(& time) and end date(&time). How do i validate these, so that a person cannot pick a time in between these? For example, if someone picks friday, 15th of June, 8-11am, another wont be able to pick friday 15th of June, 8-12pm or 8:30 – 10:00am or any time in between.

This involves comparing the current column with previously entered ones, how do i do this? I just got started on SharePoint.

Thanks in anticipation and kind regards


This isn't something which is easy using SharePoint.

The only way to validate using values from other list items is to use an EventReceiver. See Creating SharePoint 2010 Event Receivers in Visual Studio 2010

In the ItemAdding and ItemUpdating events you want to query for other items which collide with the selected datetimes.
To query for items you have to use SPList.GetItems with a CAML query something like:

      <FieldRef Name="EndDate" />
      <Value Type="DateTime>value of entered StartDate in ISO8601 format</Value>
      <FieldRef Name="StartDate" />
      <Value Type="DateTime>value of entered EndDate in ISO8601 format</Value>

To format the dates you can use SPUtility.CreateISO8601DateTimeFromSystemDateTime

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.