Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

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> 
share|improve this question

2 Answers 2

up vote 5 down vote accepted

Use 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>  
share|improve this answer
    
Perfect Thanks!! –  user7400 Mar 21 '12 at 21:00

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.

share|improve this answer
    
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
    
Perfect Thanks!! –  user7400 Mar 21 '12 at 21:00

Your Answer

 
discard

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.