8

I want to retrieve items from list which are lessthan seven days from today date.

Today date:12/14/2015

seven days means: 12/21/2015.

Using caml query. can anybody know please tell me.

1
  • C# or jquery ??
    – Gaurravs
    Commented Dec 14, 2015 at 8:50

5 Answers 5

20

In a caml query, you will need to use <Today> token with OffsetDays.

For e.g.

<Where><Leq><FieldRef Name='Your_Date_Column' /><Value Type='DateTime'><Today OffsetDays='7' /></Value></Leq></Where>

Reference: Using the Today token in a CAML query

5

Let SharePoint do the work for you

You can Filter by date in the View Filter settings,
This shows the Items created in the Last Week:

Important:

You can use spaces (and linebreaks) in a Calculated Column Formula,
but do NOT use spaces in this Filter Formula

If you do, you get the most informative message:

3
  • But if any items gets updated later week again this calculated date will get updated.
    – Gaurravs
    Commented Dec 14, 2015 at 8:57
  • This is not a Calculated Column/Field. It is a View Filter calculation, executed every time you open the View. You can put references to Calculated Columns here, but you can not use Today in a Calculated Column Commented Dec 14, 2015 at 9:21
  • FYI. Today can be used in calculated columns. I have used it several time.. just you cannot use it simply like above
    – Gaurravs
    Commented Dec 14, 2015 at 10:00
2

Use following code if using jquery:

var lastWeek = new Date();

lastWeek.setDate(lastWeek.getDate() + 7);

now you can use this variable the way you want. I hope this is what you were in need

1
objQuery.Query = "<Query><Where><And><Geq><FieldRef Name='EventDate' /><Value IncludeTimeValue='TRUE' Type='DateTime'><Today OffsetDays='7' /></Value></Geq><IsNotNull><FieldRef Name='Title' /></IsNotNull></And></Where><OrderBy><FieldRef Name='EventDate' Ascending='True' /> </OrderBy></Query>";
0

The Query where we can view the current week seems to be as below:

<Query>
  <Where>
     <DateRangesOverlap>
       <FieldRef Name='EventDate'/><FieldRef Name='EndDate'/>
       <Value Type='DateTime'>
           <Week/> 
       </Value>
     </DateRangesOverlap>
  </Where>
</Query

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.