在 CAML 查询中使用部分日期 [英] Using part of date in CAML query

查看:45
本文介绍了在 CAML 查询中使用部分日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我列表中的标题列仅包含年份.我想提出一个观点,我只展示过去 3 年的内容.

The title column in my list contains year only. I want to make a view, where I would display only last 3 years.

我正在尝试在列表定义中使用 CAML 查询:

I'm trying to use CAML query in List definition:

<Query>
  <Where>
    <Geq>
      <FieldRef Name="Year" />
      <Value Type="Number"> ???? </Value>
    </Geq>
  </Where>
</Query>

我试图在这里使用带有 Offset 属性的 <Today> 元素获得一些东西,但没有运气 - 它不是 DateTime 值,而只是一个数字.

I was trying to get something here using <Today> element with Offset attribute, but without luck - it's not a DateTime value, but only a number.

这里怎么写过滤条件?

推荐答案

由于它不是日期时间值,因此它永远不会与 offset 一起使用,因为这些元素根据查询运行的时刻在内部转换为 SQL DateTime 值.

Since it's not a datetime value ,it will never work with <Today> and offset because these elements are internally convert to SQL DateTime value based on the moment the query is run.

您可以创建一个视图,在其中查找 2009 年以上的任何条目(截至 2012 年),但这需要每年进行额外的少量工作来适应.

You could create a view where you're looking for any entry above 2009 (as of right 2012) but that would require additional minor work each year to adapt.

如果可能的话,我会建议创建一个仅实际日期的字段并使用它(并且可能只显示基于该值的计算字段).

I would suggest if possible to create a real date only field and work with it (and maybe only display a calculated field based on that value).

这篇关于在 CAML 查询中使用部分日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆