【问题标题】:How to "Filter" data having "DateTime" format according to the "CurrentDateTime" in SharePoint?如何根据 SharePoint 中的“CurrentDateTime”“过滤”具有“DateTime”格式的数据?
【发布时间】:2012-07-11 00:40:58
【问题描述】:

如何根据SharePoint中的“CurrentDateTime”“过滤”具有“DateTime”格式的数据?

我有一个名为“CreatedOn”(DateTime)的日期时间数据字段,我想应用过滤器,我想只显示“GreaterThan Or EqualTo”和“CurrentDateTime”的项目。

我在 where 条件下尝试使用此 CAML 查询但没有成功,它仅根据当前日期而不是“CurrentDateTime”进行过滤

<Where>            <Geq>              <FieldRef Name="CreatedOn"/>              <Value Type="DateTime" IncludeDateTime="TRUE">               <Today/>              </Value>             </Geq>             </Where>

感谢任何帮助。

维努

【问题讨论】:

    标签: sharepoint sharepoint-2010 sharepoint-designer


    【解决方案1】:

    您的 CAML 中需要以下属性:

    <Value IncludeTimeValue=’TRUE’ Type=’DateTime’>
    

    【讨论】:

    • 嗨 Rikard,我的代码中有这些标签(你能看看我提供的源代码吗)。但它仍然无法正常工作。
    • 不,在您的源代码中,该属性称为 IncludeDateTime,但您需要将其称为 IncludeTimeValue。有一个重要的区别。
    【解决方案2】:

    这是我从刘埃米尔那里得到的解决方案

    嗨,维努,

    请在 SharePoint Designer 中以这种方式创建数据视图 Web 部件而不是列表视图 Web 部件:

    插入 > 数据视图 > 空数据视图 > 选择您的列表 > 选择您需要在 Web 部件中显示的字段 > 将它们作为多个列表项插入。

    因为我们需要使用公式作为过滤值,但是List View Web Part不支持使用公式作为过滤值,所以需要Data View Web Part。

    使用以下公式作为过滤值,这样数据视图将只显示其 CreatedOn 字段大于或等于当前日期时间的项目。

    number(ddwrt:FormatDateTime(string(@CreatedOn),3081,'yyyyMMdd0000'))+number(ddwrt:FormatDateTime(string(@CreatedOn),3081,'HHmm'))>= number(ddwrt:FormatDateTime( string(ddwrt:TodayIso()),3081,'yyyyMMdd0000'))+数字(ddwrt:FormatDateTime(string(ddwrt:TodayIso()),3081,'HHmm'))

    以这种方式添加公式:

    将鼠标放在数据视图上 > 单击 SharePoint Designer 功能区中选项选项卡下的筛选按钮 > 启用“添加 XSLT 筛选”选项 > 单击编辑按钮 > 在此处粘贴到 XPath 上方。

    如果您有任何问题,请告诉我。

    感谢和问候, 埃米尔

    谢谢 维努

    【讨论】:

      【解决方案3】:

      这是您应该尝试的查询:

         <Where>
            <Geq>
               <FieldRef Name='CreatedOn' />
               <Value IncludeTimeValue='TRUE' Type='DateTime'><Today/></Value>
            </Geq>
         </Where>
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2021-07-17
        • 2019-01-23
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2023-03-05
        • 1970-01-01
        • 2021-03-07
        相关资源
        最近更新 更多