Search This Blog

Thursday, September 9, 2010

InfoPath-DateDifference without Code

As you all know, DateDiff doesn’t exists in InfoPath, so do we have to do when we want to calculate the number of days between 2 given dates?  Tnx Alex Pojidaev’s hto share this with the world
What do we need

- 2 date fields in the datasource, startDate, endDate

- 1 text field dayDifference
Step by Step

- Go to the datasource of your InfoPath Form

- Go to the properties of startDate field, and add a rule

            Condition:   endDate is not blank

            Actions:  Set field dayDifference = 0;4096



- Go to the properties of endDate field, and add a rule

            Condition:   startDate is not blank

            Actions:  Set field dayDifference = 0;4096


- Go to the properties of dayDifference field, and add 2 rules


       RULE 1

            Condition:   The Expression : xdDate:AddDays(../my:startDate, substring-before(., “;”)) != ../my:endDate AND

                                     DayDifference contains ;

            Actions:  Set field dayDifference = concat(substring-before(., “;”) + substring-after(., “;”) * ((translate(addDays

                         (startDate, substring-before(., “;”)), “-”, “”) < translate(endDate, “-”, “”)) * 2 – 1), “;”, substring-after(., “;”) / 2)


       (Don’t forget the select the Edit Xpath checkbox)


  RULE 2

             Condition:   DayDifference contains ;

            Actions:  Set field dayDifference = substring-before(., “;”)


Your form is ready, it works also in repeating controls.



DateDiffCodeless

1 comment: