ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

Infopath 计算两个时间日期之间差的天数,免代码

2020-03-10 12:54:29  阅读:356  来源: 互联网

标签:Infopath 12 .. floor 天数 代码 number substring div


 找了几天,终于找到一个简单一点的办法,虽然公式有点复杂,让人看不懂,但是效果很好,月份不一样也可以。

I was able to find a product that I used to resolve the "delta" = the difference between dates.

 The link is listed:  http://www.bizsupportonline.net/infopath2007/calculate-date-difference-infopath-rules-formulas.htm

 Calculate the difference between two date picker controls in InfoPath using rules and formulas - no code!

by S.Y.M. Wong-A-Ton | Applies to: InfoPath 2007

Use rules, conditions, and the number(), floor(), and substring() functions in formulas to calculate the difference between two date picker controls in InfoPath.

Use rules, conditions, and the number(), floor(), and substring() functions in formulas to calculate the difference between two date picker controls in InfoPath.

 

Problem

You have a form template with two InfoPath date picker controls and you would like to calculate the difference between the two date picker controls without writing code.

Solution

Use rules, conditions, and the number(), floor(), and substring() functions in formulas to calculate the difference between two date picker controls in InfoPath.

Discussion

You can accomplish this functionality as follows:

  1. Design an InfoPath form template as shown in figure 1 with two Date Picker controls named startDate and endDate, and one Text Box control named difference.

    Figure 1. InfoPath form template in Design mode.

    The Main data source of the InfoPath form template should resemble the following figure:


    Figure 2. The Main data source of the InfoPath form template.
  2. Add the following Rule to the startDate field:
    Action: Set a field's value
    Field: difference
    Value: (number(substring(../my:endDate, 9, 2)) + floor((153 * (number(substring(../my:endDate, 6, 2)) + 12 * (floor((14 - number(substring(../my:endDate, 6, 2))) div 12)) - 3) + 2) div 5) + (number(substring(../my:endDate, 1, 4)) + 4800 - (floor((14 - number(substring(../my:endDate, 6, 2))) div 12))) * 365 + floor((number(substring(../my:endDate, 1, 4)) + 4800 - (floor((14 - number(substring(../my:endDate, 6, 2))) div 12))) div 4) - floor((number(substring(../my:endDate, 1, 4)) + 4800 - (floor((14 - number(substring(../my:endDate, 6, 2))) div 12))) div 100) + floor((number(substring(../my:endDate, 1, 4)) + 4800 - (floor((14 - number(substring(../my:endDate, 6, 2))) div 12))) div 400) - 32045) - (number(substring(., 9, 2)) + floor((153 * (number(substring(., 6, 2)) + 12 * (floor((14 - number(substring(., 6, 2))) div 12)) - 3) + 2) div 5) + (number(substring(., 1, 4)) + 4800 - (floor((14 - number(substring(., 6, 2))) div 12))) * 365 + floor((number(substring(., 1, 4)) + 4800 - (floor((14 - number(substring(., 6, 2))) div 12))) div 4) - floor((number(substring(., 1, 4)) + 4800 - (floor((14 - number(substring(., 6, 2))) div 12))) div 100) + floor((number(substring(., 1, 4)) + 4800 - (floor((14 - number(substring(., 6, 2))) div 12))) div 400) - 32045) with the following Conditions on the Rule:
    startDate is not blank and
    endDate is not blank
  3. Add a second Rule to the startDate field with the following settings:
    Action: Set a field's value
    Field: difference
    Value: 0

    with the following Conditions on the Rule:
    startDate is blank or
    endDate is blank
  4. Add the following Rule to the endDate field:
    Action: Set a field's value
    Field: difference
    Value: (number(substring(., 9, 2)) + floor((153 * (number(substring(., 6, 2)) + 12 * (floor((14 - number(substring(., 6, 2))) div 12)) - 3) + 2) div 5) + (number(substring(., 1, 4)) + 4800 - (floor((14 - number(substring(., 6, 2))) div 12))) * 365 + floor((number(substring(., 1, 4)) + 4800 - (floor((14 - number(substring(., 6, 2))) div 12))) div 4) - floor((number(substring(., 1, 4)) + 4800 - (floor((14 - number(substring(., 6, 2))) div 12))) div 100) + floor((number(substring(., 1, 4)) + 4800 - (floor((14 - number(substring(., 6, 2))) div 12))) div 400) - 32045) - (number(substring(../my:startDate, 9, 2)) + floor((153 * (number(substring(../my:startDate, 6, 2)) + 12 * (floor((14 - number(substring(../my:startDate, 6, 2))) div 12)) - 3) + 2) div 5) + (number(substring(../my:startDate, 1, 4)) + 4800 - (floor((14 - number(substring(../my:startDate, 6, 2))) div 12))) * 365 + floor((number(substring(../my:startDate, 1, 4)) + 4800 - (floor((14 - number(substring(../my:startDate, 6, 2))) div 12))) div 4) - floor((number(substring(../my:startDate, 1, 4)) + 4800 - (floor((14 - number(substring(../my:startDate, 6, 2))) div 12))) div 100) + floor((number(substring(../my:startDate, 1, 4)) + 4800 - (floor((14 - number(substring(../my:startDate, 6, 2))) div 12))) div 400) - 32045) with the following Conditions on the Rule:
    startDate is not blank and
    endDate is not blank
  5. Add a second Rule to the endDate field with the following settings:
    Action: Set a field's value
    Field: difference
    Value: 0

    with the following Conditions on the Rule:
    startDate is blank or
    endDate is blank
  6. Add the following Rule to the difference field:
    Action: Set a field's value
    Field: .
    Value: 0

    with the following Condition on the Rule:
    difference does not match pattern Custom Pattern: -{0,1}\d+

You should now have a fully functional InfoPath form that will calculate the difference between the dates soon after you have entered valid dates. This solution also works for InfoPath 2003 form templates and InfoPath 2007 browser-enabled form templates. 

标签:Infopath,12,..,floor,天数,代码,number,substring,div
来源: https://www.cnblogs.com/jpinsz/p/12455011.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有