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

i have a problem with a CAML Query for a Sharepoint Online(Office365) Calendar. I try to get all Calendar Appointments between two dates. Here is my code:

        private void getFreeDays()
        List urlaubskalender = clientContext.Web.Lists.GetByTitle("Urlaubskalender");

        DateTime startDate = Convert.ToDateTime(dpEventDate.SelectedDate);
        DateTime endDate = Convert.ToDateTime(dpEndDate.SelectedDate);

        CamlQuery getDatesQuery =new CamlQuery();
        getDatesQuery.ViewXml = "<Query>"+
                                                "<FieldRef Name='EventDate' />"+
                                                    "<Value Type='DateTime'>"+startDate+"</Value>"+
                                                "<FieldRef Name='EndDate' />"+
                                                    "<Value Type='DateTime'>"+endDate+"</Value>"+

        eventCollection = urlaubskalender.GetItems(getDatesQuery);

        clientContext.ExecuteQueryAsync(new ClientRequestSucceededEventHandler(onQSGetEvents), null);

The Problem is that I get appointments from 01.01.2013 when I select 01.02.2013 as EventDate and 08.02.2013 as EndDate. The appointment is a reccurent one, maybe this is the cause of the problem? I tried to find some informations to create a CAML Query without recurring appointment but i couldn't found something. Maybe the failure is something total different...

I hope someone can help me...and sorry for my bad english, i gave my best ;)

share|improve this question

You need to use the SPUtility.CreateISO8601DateTimeFromSystemDateTime() method to get your date times in the proper format.

share|improve this answer
Thanks for your answer. I use the Client Object Model. There is just a Class called ClientUtility ( ). It has no method CreateISO8601DateTimeFromSystemDateTime() or something like this. Do you know a workaround for my issue? – Alexander Feb 5 '13 at 10:18

I have solved the problem. I can change the format of the DateTime variable with startDate.ToString("yyyy-MM-ddTHH:mm:ssZ")

I have build the query with the U2U Query Builder (great tool!) here is the query if someone is interested in thisgetDatesQuery.ViewXml = "<Query>" + "<Where>" + "<And>" + "<Eq>" + "<FieldRef Name='fRecurrence' />" + "<Value Type='Recurrence'>false</Value>" + "</Eq>" + "<And>" + "<Leq>" + "<FieldRef Name='EventDate' />" + "<Value IncludeTimeValue='TRUE' Type='DateTime'>" + startDate.ToString("yyyy-MM-ddTHH:mm:ssZ") + "</Value>" + "</Leq>" + "<Geq>" + "<FieldRef Name='EndDate' />" + "<Value IncludeTimeValue='TRUE' Type='DateTime'>" + endDate.ToString("yyyy-MM-ddTHH:mm:ssZ") + "</Value>" + "</Geq>" + "</And>" + "</And>" + "</Where>" + "<OrderBy>" + "<FieldRef Name='EventDate' Ascending='True' />" + "</OrderBy>" + "</Query>";

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.