I have a problem with SPQuery and DataRangesOverlap.

In my calendar there are three events that don't happen today. In SPQuery.query I want to exclude these events. Unfortunately all events are returned. The contains filter for a text column works fine but the DataRangesOverlap doesn't do any filtering. Here is my code:

SPListCollection oLists = oSiteCollection.AllWebs["MYSITE"].Lists;
String res = "";
SPQuery spquery = new SPQuery();
string datasel = SPUtility.CreateISO8601DateTimeFromSystemDateTime(caldata.SelectedDate.Date);

spquery.Query = "<Where><And><DateRangesOverlap><FieldRef Name=\"EventDate\" /><FieldRef Name=\"EndDate\" /><FieldRef Name=\"RecurrenceID\" /><Value Type=\"DateTime\" IncludeTimeValue=\"True\">Today</Value></DateRangesOverlap><Or><Contains><FieldRef Name=\"Title\" /><Value Type=\"Text\">" + tbnome.Text + "</Value></Contains></Or></And></Where>";
spquery.ExpandRecurrence = true;
spquery.RowLimit = 100;

foreach (SPList l in oLists)  {
  String title =  l.Title;
  if (title.IndexOf("MyCalendar")==0)  {

    SPListItemCollection items = l.GetItems(spquery);

    foreach (SPListItem item in items)
      res += "<li>" + item["Title"]  + " date1 " + item["Start Time"] + " date2 " + item["End Time"] + "</li>";
res = "<ul>"+res+"</ul>";

I wrote

<Value Type=\"DateTime\" IncludeTimeValue=\"True\">Today</Value>

instead of

<Value Type=\"DateTime\" IncludeTimeValue=\"True\"><Today /></Value>
| improve this answer | |

Unfortunately, the caml date stuff pretty much sucks in SharePoint. It won't compare based on time and I think the daterangesoverlap only works for recurring events. Are the events you expect NOT to be shown recurring or single instance events?

| improve this answer | |

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.