[英]Query on Date Fields using CAML
I am trying to run a query against a sharepoint list (using the client object model), finding an item that matches on a date field. 我试图对一个共享点列表(使用客户端对象模型)运行查询,找到一个与日期字段匹配的项目。
My query is: 2012-07-24T02:50:28 1 我的查询是:2012-07-24T02:50:28 1
I know that there is an item in the list where the EmDateSent field has the value 2012-07-24T02:50:28 and yet when I run this I get 0 rows back. 我知道列表中有一个项目,其中EmDateSent字段的值是2012-07-24T02:50:28,但是当我运行它时,我得到了0行。
Having spent hours researching and experimenting I found that the date formatting I have used works - or so I thought. 花了数小时进行研究和实验后,我发现我使用的日期格式确实有效-大概是这样。 It seems that now it doesn't.
看来现在没有。
My code is below. 我的代码如下。
Can anybody suggest something else I can try? 有人可以建议我尝试一下吗?
CamlQuery camlQuery = new CamlQuery();
camlQuery.ViewXml = String.Format(
@"<View>
<Query>
<Where>
<Eq>
<FieldRef Name='{0}'/>
<Value Type='DateTime' IncludeTimeValue='True'>{1}</Value>
</Eq>
</Where>
</Query>
</View>", EMAIL_FIELD_DATE_SENT, details.DateSent.HasValue ? details.DateSent.Value.ToString("yyyy-MM-ddTHH:mm:ss") : "");
ListItemCollection listItems = upLoadList.GetItems(camlQuery);
_context.Load(listItems);
_context.ExecuteQuery();
if (listItems.Count > 0) // At this point I expect listItems.Count to be 1, but it is 0
{
....
Your example looks correct, and there is not an issue with using the "T" in the time stamp. 您的示例看起来正确,并且在时间戳中使用“ T”没有问题。 However, from what I can find, most of the examples like yours use the
SPQuery
class instead of the CamlQuery
class . 但是,据我发现,像您一样的大多数示例都使用
SPQuery
类而不是CamlQuery
类 。 I believe this is causing your issue. 我相信这是造成您问题的原因。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.