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've been trying to get all events that are today as a test, I haven't been able to do that either. So far I've set an event for today (an all day event so times don't matter) and executed this query:

<Where>
  <Contains>
    <FieldRef Name='StartDate' />
      <Value Type='Date'>
        <Now />
      </Value>
    </FieldRef>
  </Contains>
</Where>

but still no luck.

share|improve this question
    
Did you get this working? –  Steve Lineberry Jan 8 '13 at 2:27
    
Yeah, here's my query: <Where><Eq><FieldRef Name='EventDate' /> <Value Type='DateTime'><Today /> </Value></Eq></Where> –  cbrad Jan 8 '13 at 6:28
    
Ok, cool, and that works with recurring events? Or is recurring events not a case you are concerned with? –  Steve Lineberry Jan 8 '13 at 18:04
    
It doesn't matter, as long as there is an event that day, it will fire. It checks every 24 hours. –  cbrad Jan 10 '13 at 1:32
add comment

2 Answers

Start Date in the calendars has an internal name of EventDate. Try that instead, otherwise the CAML looks good to me.

share|improve this answer
    
Thanks, didn't know that. –  cbrad Dec 21 '12 at 2:31
    
This is a great tool to help with constructing CAML queries, sharepoint.biwug.be/SitePages/Caml_Designer.aspx –  PirateEric Dec 21 '12 at 16:32
add comment

Because recurring event's exist this has been difficult for me in the past. I've usually had to limit it to a particular month and then eliminate items that didn't meet my criteria in code after the query returns. I know it sucks but it's the only way I've been able to get all of the events.

Below is the spquery code I've used before. The key is the expandrecurrance and the calendardate properties.

SPQuery eventQuery = new SPQuery();
eventQuery.ExpandRecurrence = true;
eventQuery.CalendarDate = new DateTime("12/20/2012");

The SPUtility.CreateISO8601DateTimeFromSystemDateTime function is handy when trying to create your caml. Below is some caml that worked for me, the key is the daterangesoverlap section which helps bring in all of the recurring events for the month. Also, since i'm usually outputting a monthly calendar, I bring in events from the previous and next months to make sure they show correctly when the monthly calendar shows events in the same week for a previous or next month. You can probably adjust the dates to be more exact since you are talking about a single day.

<Where>
    <Or>
        <DateRangesOverlap>
            <FieldRef Name="EventDate" />
            <FieldRef Name="EndDate" />
            <FieldRef Name="RecurrenceID" />
            <Value Type="DateTime">
                <Month>12</Month>
                <Year>2012</Year>
            </Value>
        </DateRangesOverlap>
        <Or>
            <And>
                <Geq>
                    <FieldRef Name='EventDate' />
                    <Value Type='DateTime'>2012-11-20T00:00:00Z</Value>
                </Geq>
                <Leq>
                    <FieldRef Name='EventDate' />
                    <Value Type='DateTime'>2013-01-20T00:00:00Z</Value>
                </Leq>
            </And>
            <And>
                <Geq>
                    <FieldRef Name='EndDate' />
                    <Value Type='DateTime'>2012-11-20T00:00:00Z</Value>
                </Geq>
                <Leq>
                    <FieldRef Name='EndDate' />
                    <Value Type='DateTime'>2013-01-20T00:00:00Z</Value>
                </Leq>
            </And>
        </Or>
    </Or>
</Where>
share|improve this answer
    
Going to give this a try. Thanks for your detailed input! –  cbrad Dec 21 '12 at 2:32
    
So this will only work for year 2012 - 2013 right? Can I format the date returned from the DateTime method so that I can use it in the query? –  cbrad Dec 21 '12 at 2:37
    
Yea, I was just showing you the final result of my query. I created the query in code and used the appropriate dates. –  Steve Lineberry Dec 21 '12 at 3:27
    
Ok cool. So the second event date in the query is the date later than the first correct? So in my query I would have the date today as the first date in the query, and then add 1 day to today as my second date in the query? –  cbrad Dec 21 '12 at 16:32
    
Well, my caml above is something like this in pseudo code: Return event if (a recurring event overlaps for the month 12/2012) OR ((EventDate > 11/20/2012 and EventDate < 01/20/2013) OR (EndDate > 11/20/2012 and EndDate < 01/20/2013)) Since you are only doing it for one day, you may not need the range of dates like I have. But you will have to play around with it to be sure. –  Steve Lineberry Dec 21 '12 at 16:38
add comment

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.