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> 
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>  
  • 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 5:36
  • i resolved this issue by simple making IncludeTimeValue='TRUE' to IncludeTimeValue='FALSE' – Madhav Apr 18 '16 at 6: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.

  • Hey Zork I just posted my Query. If you take a look at it, where I have specified now() there is <Value IncludeTimeValue='TRUE' Type='DateTime'>2012-03-21T12:18:55Z</Value> 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

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.