How to calculate date difference with XPath only?

2019-08-26 10:02发布

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条回答
SAY GOODBYE
2楼-- · 2019-08-26 10:48

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'
查看更多
登录 后发表回答