I have been working on aggregating calendar events from different calendar lists present in different sub sites of a site collection and surfacing them through JQuery full calendar. Since the calendar list can have recurring events and information about each recurrence was needed that means I had to use DateRangesOverlap queries.
In this post I will share my findings about DateRangesOverlap queries.
Observe that there is one event from previous day ( 26th May 2015). In case of Now all the events starting from today till 2 years from today are shown. Sample code:
In this post I will share my findings about DateRangesOverlap queries.
- Using queries having DateRangeOverlap value set to Now:
Following is the list of events present in the calendar list. Keep in mind that the date of the day I am testing it is 27th May 2015.
Calendar Events |
SPList list = web.Lists["Company Calendar"];
SPQuery oQuery = new SPQuery();
oQuery.ExpandRecurrence = true;
oQuery.Query = "<Where><DateRangesOverlap><FieldRef Name='EventDate' />" +
"<FieldRef Name='EndDate' /><FieldRef Name='RecurrenceID' />" +
"<Value Type='DateTime'><Now /></Value>" +
"</DateRangesOverlap></Where>";
oQuery.CalendarDate = DateTime.Now;
SPListItemCollection items = list.GetItems(oQuery);
foreach(SPListItem item in items)
{
Console.WriteLine("Title: {0}, StartDate: {1}", item.Title, item["EventDate"]);
}
Here is the output from above code:
As can be seen it does't show the previous events and any future events beyond 2 years from today. Now we may be tempted to set the CalendarDate to previous date and expect the previous events to show up. However, whatever be the value of CalendarDate be it always shows events from today and future events within two years.
- Using queries having DateRangeOverlap value set to Today:
As the name suggests it only shows events happening on the current date. However, it does honor the CalendarDate property. That is, if we set the CalendarDate to previous or future date, it shows the events from that day. Sample code to show events happening tomorrow:
Change oQuery.CalendarDate = DateTime.Now; to
Change oQuery.CalendarDate = DateTime.Now; to
oQuery.CalendarDate = DateTime.Now.AddDays(1);
in the sample code used earlier. Here is the output:- Using queries having DateRangeOverlap value set to Year:
This returns previous events happening withing a year from current date and future events happening withing a year from current date. CalendarDate property doesn't seem to have any effect. Here is the output using Year
Observe the first and last entry. Keep in mind that I am running this code on May 27th 2015.
- Using queries having DateRangeOverlap value set to Month:
The Month option shows events of the given month along with events from last seven days of previous month and future seven days of next month. CalendarDate property only takes the month portion into consideration. So, if today is May 27, 2015, and oQuery.CalendarDate = DateTime.Now; then the output will be all events of May 2015, plus events from 24th April on wards from previous month and similarly events till 7th June in next month. Here is the sample output:
Notice the first and last event. Even though the list contains events for 23 April 2015 and 8th June 2015, they don't show up. Now, even if the CalendarDate property is set to May 01, 2015; the result will still be same as above since it is the only month part of date which is considered. However, changing the date to April 30, 2015 will give all events of April, events from last seven days of March and events from first seven days of May. Here is the output with April 30, 2015 as CalendarDate
- Using queries having DateRangeOverlap value set to Week:
The Week option shows events of the given week (Sunday to Saturday) and the events of Sunday of next week. So, if CalendarDate property is set to 27th May 2015, the events from 24th May till 31st May will show up as can be seen in the screen shot:
Similarly, if CalendarDate property is set to 23rd May 2015, the events from 17th May till 24th May will show up as can be seen in the screen shot:
To summarize, Now and Year do not honor the CalendarDate property whereas Month, Today and Week do honor it.
You may like to visit SharePoint: JQuery Full Calendar
You may like to visit SharePoint: JQuery Full Calendar