Second Life of a Hungarian SharePoint Geek

March 4, 2008

Using Month element in DateRangesOverlap can return items not in the specified month

Filed under: Calendar, CAML, SharePoint — Tags: , , — Peter Holpar @ 23:02

One can logically think that if you set the CalendarDate property of the SPQuery and apply Month as the Value in the DateRangesOverlap element then the query returns items from the month specified in the CalendarDate property.

For example, using the following code …

SPQuery query = new SPQuery();
query.CalendarDate = new DateTime(2008, 3, 1);

… and applying the following CAML query …

<FieldRef Name='StartDate' />
<FieldRef Name='EndDate' />
<Value Type='DateTime'>
<Month />

… one can expect that items having overlap with March 2008 will be only returned.

I’ve found that it is not exactly so, as elements from the end of February and beginning of April may be also returned. The reason for that I think is the simple fact that these items have overlap with the calendar range of the month view of March 2008 (e.g. 24/02/2008-05/04/2008), as the month calendar view includes the full weeks at the beginning and the end of the month, not only the days between 01/03/2008-31/03/2008.

Since DateRangesOverlap is (another) under-documented element of SharePoint and CAML I can’t decide if it is a bug or a feature. Since it is used primarily in the calendar views it seems to be logical that it should return all items that need to be displayed in the month view. So it is probably by design, sad that this fact is not documented.

This fact caused a misbehavior (or let’s call it bug) in one of our custom application, so we should return to our original complex CAML query assembled from Lt, Gt, Leq, Geq, composite And and Or elements…


  1. […] Nothing is perfect. DateRangesOverlap has a little issue when filtering for a given month. You can read about that in my former post: Using Month element in DateRangesOverlap can return items not in the specified month. […]

    Pingback by Creating view to display list items created in the current month « Second Life of a Hungarian SharePoint Geek — December 5, 2009 @ 00:50

  2. Greetings,
    I had a query regarding the recurring events.
    I was wondering if SPSiteDataQuery could in some way replicate what ExpandRecurrence does for SPQuery.
    I am currently unable to view recurring events using SPSiteDataQuery as looping through all the present websites using SPQuery seems like a serious load on my page.
    Thanks in advance
    Sanjay Hari

    Comment by Sanjay — February 18, 2010 @ 14:59

  3. Hi Sanjay Hari,

    Unfortunately, SPSiteDataQuery misses the ExpandRecurrence property. You should apply some kind of workaround, for example, aggregate all events on your web sites into a single calendar using event receivers (ItemAdded, ItemUpdated, ItemDeleted) on each calendar lists, and use SPQuery on this “master” calendar.

    Hope that helps.


    Comment by pholpar — February 18, 2010 @ 16:49

  4. Thank you for the input Peter.

    Comment by Sanjay — April 8, 2010 @ 09:39

RSS feed for comments on this post. TrackBack URI

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

Blog at

%d bloggers like this: