1

i am trying to get the 3 most upcoming events from the current date and time (The current data and time refers the time everytime my web part loads. Basically it is not a fixed date and picks up the time everytime my web part is loaded) Here is my Query. How should I modify it to achieve this?

 <Query>
 <Where>
  <And>
     <Geq>
        <FieldRef Name='EventDate' />
        <Value IncludeTimeValue='TRUE' Type='DateTime'>2012-03-21T12:18:55Z</Value>
     </Geq>
     <IsNotNull>
        <FieldRef Name='Title' />
     </IsNotNull>
  </And>
 </Where>
<OrderBy>
  <FieldRef Name='EventDate' Ascending='True' />
</OrderBy>
</Query> 
user7400
  • 1,266
  • 7
  • 42
  • 66

2 Answers2

6

Use <Today/> instead of the hardcoded value

<Query> 
 <Where> 
  <And> 
     <Geq> 
        <FieldRef Name='EventDate' /> 
        <Value IncludeTimeValue='TRUE' Type='DateTime'><Today /></Value> 
     </Geq> 
     <IsNotNull> 
        <FieldRef Name='Title' /> 
     </IsNotNull> 
  </And> 
 </Where> 
 <OrderBy> 
  <FieldRef Name='EventDate' Ascending='True' /> 
 </OrderBy> 
</Query>  
Per Jakobsen
  • 32,409
  • 1
  • 33
  • 62
  • sorry,Per Jakobsen but its not working for me, n by simply looking at the code ,it's have to work but unfortunately it's not working for me,it's showing all the events from list. – Madhav Apr 18 '16 at 05:36
  • i resolved this issue by simple making IncludeTimeValue='TRUE' to IncludeTimeValue='FALSE' – Madhav Apr 18 '16 at 06:51
2

You can accomplish this by querying for all events greater than now() ordered by date, ascending. Then limit the query to 3 rows and you have all your data!

Let me know if you need help creating the query itself, and please post what you have if you do.

Zork
  • 1,560
  • 2
  • 14
  • 23
  • Hey Zork I just posted my Query. If you take a look at it, where I have specified now() there is 2012-03-21T12:18:55Z Will this change accordingly during runtime? – user7400 Mar 21 '12 at 20:38
  • Per posted it before i could do it! his code should work perfectly – Zork Mar 21 '12 at 20:41