5

I'm trying to perform a CAML Query test and display the results.

For example I'll be using two columns in a list; one called StartDate another called EndDate.

Currently, I've a CAML Query that orders the StartDate column and displays the first five items in the list.

    CAMLQuery: "<Query><OrderBy><FieldRef Name='StartDate' Ascending='True'/></OrderBy></Query>",
    CAMLRowLimit: 5, 

What I need to do is to write something that will look at the EndDate column and make a comparison to today's date. If that date has already passed it shouldn't turn up in the results.

Therefore, the 5 list items appearing will not have an EndDate that has already passed.

Dikesh Gandhi
  • 6,803
  • 4
  • 30
  • 55
  • Take a look at http://sharepoint.stackexchange.com/questions/49433/caml-now-instead-of-today-caml-bug The snippet at the very top of the page might be really close to what you need - I believe you'll need to place it here in your Query – Hutch Jan 08 '16 at 01:01

1 Answers1

5

You will need to add where condition and use <Today> token in your caml query. The query will be like as below

<OrderBy>
    <FieldRef Name='StartDate' Ascending='True'/>
</OrderBy>
<Where>
    <Geq>
        <FieldRef Name='EndDate' /><Value Type='DateTime'><Today /></Value>
    </Geq>
</Where>

Reference: http://www.sharepoint-tips.com/2009/06/using-today-token-in-caml-query.html

P S
  • 4,827
  • 4
  • 27
  • 50