CAML中通过时间的查询需要注意时间的格式问题,查询结果才是正确的。
查询有效期大于今天的数据
例子:
string dString = SPUtility.CreateISO8601DateTimeFromSystemDateTime(DateTime.Now); SPQuery query = new SPQuery(); query.Query = string.Format("<Where><Gt><FieldRef Name=\"Expires\" /><Value IncludeTimeValue=\"TRUE\" Type=\"DateTime\">{0}</Value></Gt></Where><OrderBy><FieldRef Name=\"Created\" Ascending=\"False\" /></OrderBy>", dString); query.ViewFields = "<FieldRef Name=\"LinkTitle\"/><FieldRef Name=\"ID\"/>"; query.RowLimit = 5; SPListItemCollection listItems = list.GetItems(query);