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.

Niranjan Kulkarni
  • 1,027
  • 1
  • 13
  • 34
user48785
  • 81
  • 1
  • 1
  • 2

5 Answers5

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

P S
  • 4,827
  • 4
  • 27
  • 50
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:

Danny '365CSI' Engelman
  • 21,176
  • 7
  • 35
  • 79
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

Gaurravs
  • 3,558
  • 12
  • 22
  • 33
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>";
Madhav
  • 1,494
  • 1
  • 16
  • 26
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
Patrick Jane
  • 41
  • 1
  • 3