Tell me more ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I'm trying to get all list item in a calendar scheduled within 30 day of a given date.

            ndQueryOptions.InnerXml = "<ExpandRecurrence>TRUE</ExpandRecurrence>";
            ndQueryOptions.InnerXml += "<CalendarDate>" + calendarDate + "</CalendarDate>";
            ndQueryOptions.InnerXml += "<ViewAttributes Scope=\"RecursiveAll\" />";

            ndQuery.InnerXml = @"<Where><DateRangesOverlap><FieldRef Name=""EventDate"" /><FieldRef Name=""EndDate"" /><FieldRef Name=""RecurrenceID"" /><Value Type=""DateTime""><Now /></Value></DateRangesOverlap></Where><OrderBy><FieldRef Name=""EventDate"" /></OrderBy>";

Then I massage the data to get the data within the date range.

It seems to work if the given date is within a particular range. For example, I have an event for every Wednesday and Friday. if now is 6/5/2013, it returns data from now till 9/13/2013. Any query (for the given date) other than those two days (an earlier date like 4/5/2013 or a later date like 10/1/2014) returns no events between the date range.

Update: I changed the <Value Type=""DateTime""><Year /></Value> from <Now />, result is better that it does return some historical data, but not to previous year, nor to next year.

Update: I followed Douglas's suggestion, it missed the DateRangesOverlap part, so it only returns one node for the recurrent event instead of unfolded them. So I don't think it works.

Update: I found an article explaining the value type for the DateRangesOverlap. Here confirms that <Year /> only returns data from today and does not work with calendar date (the start date I wanted it to be). According to that article, <Month /> is more reliable. So I can't do a date range search (at least not within a single web service call). I will use <Month /> instead.

share|improve this question

1 Answer

You can have a try the following query string:

<Where><And><Leq><FieldRef Name='EventDate' /><Value Type='DateTime'>...</Value></Leq><Geq><FieldRef Name='EndDate' /><Value Type='DateTime'>...</Value></Geq></And></Where>

and specify the value of start date and end date with format like this 2013-06-01T00:00:00.

share|improve this answer
I put String ndQueryString = String.Format(@"<Where><And><Leq><FieldRef Name=""EventDate"" /><Value Type=""DateTime"">{0}</Value></Leq><Geq><FieldRef Name=""EndDate"" /><Value Type=""DateTime"">{1}</Value></Geq></And></Where>", startDay, lastDay); where startDay and last Day are DateTime fields. It returns nothing. – user1541389 13 hours ago
Correction, I changed the startDay and lastDay with the format you mentioned above, it started to getting data, but it treated everyday having events for recurrent events. I guess I need to change my method of massaging those data. – user1541389 13 hours ago
Hi Douglas, I don't think this works since it misses the `<DateRangesOverlap>...</DateRangesOverlap> so it is not doing the unfolding of the recurrent events. – user1541389 11 hours ago

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.