Wednesday, April 22, 2009

Getting list item updated in past few days

Scenario:

Solution:
SPQuery Zindabad, I mean SPQuery is the best :-)
Also few things to note are

1. IncludeTimeValue="True"
2. SPUtility.CreateISO8601DateTimeFromSystemDateTime method

Code:

SPList list = web.Lists["Shared Documents"];

SPQuery query = new SPQuery(); 

string timeFrame = 
SPUtility.CreateISO8601DateTimeFromSystemDateTime(DateTime.Now.AddDays(-7)); 

// Build our query. Note the use of IncludeTimeValue="True" to check against time 
query.Query = @" 
<Where> 
<Gt> 
<FieldRef Name=""LastPageHitTime"" /> 
<Value IncludeTimeValue=""TRUE"" Type=""DateTime"">" + timeFrame + @"</Value> 
</Gt> 
</Where>"; 

SPListItemCollection items = list.GetItems(query);

0 comments: