如何仅使用XPath计算日期差? [英] How to calculate date difference with XPath only?
问题描述
我在使用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:
- 如果日期已过,则显示过期"
- 如果不是,则显示到给定日期为止的剩余天数
是否可以不编写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屋!