如何仅使用XPath计算日期差? [英] How to calculate date difference with XPath only?

查看:180
本文介绍了如何仅使用XPath计算日期差?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在使用InfoPath创建的表单中有一个日期字段,该字段允许用户输入日期,该日期大概是任务的截止日期.我想要另一个计算值"字段:

I have a date field in the form created using InfoPath, that allows the users to enter a date, which presumably is the due date of a task. And I want to have another "calculated value" field to:

  1. 如果日期已过,则显示过期"
  2. 如果不是,则显示到给定日期为止的剩余天数

是否可以不编写VB/C#代码,而只需将表达式粘贴到XPath对话框中?

Is this possible without writing VB/C# code, but just pasting an expression into the XPath dialog box?

谢谢!

推荐答案

假设这是用户输入日期值的xml节点

Assuming this is your xml node where user enters date value

    <due-date>2012-02-08</due-date>

然后,如果输入的日期早于当前日期,则xpath表达式下方将返回截止日期的剩余天数,如果输入的日期超过当前日期,则返回过期".

then below xpath expression will return the days remaining for the due-date if the date entered is before the current-date and returns 'OverDue' if the entered date passes current-date.

    if((xs:date(current-date())) <= (xs:date(/due-date))) 
     then days-from-duration( (xs:date(/due-date)) - (xs:date(current-date())) ) 
     else 'OverDue'

这篇关于如何仅使用XPath计算日期差?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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