SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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

share|improve this question

migrated from Jul 3 '12 at 14:35

This question came from our site for professional and enthusiast programmers.

up vote 0 down vote accepted

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

share|improve this answer

Your Answer


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.