How to calculate date difference with XPath only?

大兔子大兔子 提交于 2019-12-25 01:19:17

问题


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. if the the date has passed, then show "overdue"
  2. if not, then show the number of days left till the given date

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

Thanks!


回答1:


Assuming this is your xml node where user enters date value

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

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'


来源:https://stackoverflow.com/questions/9169650/how-to-calculate-date-difference-with-xpath-only

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!