0

I am developing an application using SPServices I want to track the existing events in a calendar based on posted start date and end date.

my query:

CAMLQuery: "<Query><Where><And><Leq><FieldRef Name='EventDate'/><Value Type='Text'>"+PostedStartDate+"</Value></Leq><Geq><FieldRef Name='EndDate'/><Value Type='Text'>"+PostedStartDate+"</Value></Geq></And></Where></Query>",

but it does not bring events greater then this date for example if my PostedEndDate is greater then event start date.

how to query all events between posted start date and end date

0

As it is a DateTime field, you have to specify it on the query. This is the correct CAMLQuery:

<Query>
    <Where>
        <And>
            <Leq>
                <FieldRef Name='EventDate'/>
                <Value Type='DateTime'>"+PostedStartDate+"</Value>
            </Leq>
            <Geq>
                <FieldRef Name='EndDate'/>
                <Value Type='DateTime'>"+PostedStartDate+"</Value>
            </Geq>
        </And>
    </Where>
</Query>

Besides, you can use IncludeTimeValue to include the time in the field.

  • It does not include situations for example if the event date start is greater and end date is less or greater then the conditions become false – Mehdi Jalal Jan 28 '18 at 6:30
0

Try this:

   <Where>
      <Or>
         <And>
            <Gt>
               <FieldRef Name='EventDate' />
               <Value Type='DateTime'>2018-01-24T12:00:00Z</Value>
            </Gt>
            <Lt>
               <FieldRef Name='EndDate' />
               <Value Type='DateTime'>2018-01-31T12:00:00Z</Value>
            </Lt>
         </And>
         <Gt>
            <FieldRef Name='EndDate' />
            <Value Type='DateTime'>2018-01-26T12:00:00Z</Value>
         </Gt>
      </Or>
   </Where>

I would also suggest to use CAML Designer to build CAML:

Caml Designer 2013

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.