1

I want to return the events in an Event Calendar for the current week for a web page. I would prefer the current week Friday through Sunday, but that seemed too complicated.
When I use this code it returns events starting approximately 1 week from now and it's showing some events two months from now. I've tried using Week instead of the offset days and that didn't return anything. Would be happy just to get today + next seven days events. Any insight into this would be greatly appreciated. Please see query:

function getMyListData()
    {                     
            var method = "GetListItems";                 
            var webURL =  $().SPServices.SPGetCurrentSite() ;                     
            var list = "Events Calendar";                      
            var fieldsToRead = "<ViewFields>"+"<FieldRef Name='Name' />" +"</ViewFields>";
            var query = "<Query><Where><Geq><FieldRef Name='EventDate' /><Value IncludeTimeValue='TRUE' Type='DateTime'><Today OffsetDays='7' /></Value></Geq></Where><OrderBy><FieldRef Name='EventDate' Ascending='True' /> </OrderBy></Query>";                       
3

Your query is just looking for any Event Date which is greater than or equal to today plus 7 days (so essentially you are looking at next week onwards). To simply show Event Dates for the next 7 days:

<Query>
    <Where>
        <And>
            <Geq>
                <FieldRef Name='EventDate' />
                <Value IncludeTimeValue='TRUE' Type='DateTime'>
                    <Today OffsetDays='0' />
                </Value>
            </Geq>
            <Leq>
                <FieldRef Name='EventDate' />
                <Value IncludeTimeValue='TRUE' Type='DateTime'>
                    <Today OffsetDays='7' />
                </Value>
            </Leq>
        </And>
    </Where>
    <OrderBy>
        <FieldRef Name='EventDate' Ascending='True' /> 
    </OrderBy>
</Query>
  • That worked great. Thx. But when I put the query on separate lines it never works. I amended your code to one line and put quotes around the whole thing and it worked. Do you know why, because it makes it really hard to read this way. Thanks! – Ginger22 Aug 9 at 13:27

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.