Help please-Solve: Number of days = (todays date - date initiated) ???? - InfoPath Dev
in

InfoPath Dev

Use our Google Custom Search for best site search results.

Help please-Solve: Number of days = (todays date - date initiated) ????

Last post 07-30-2018 07:57 AM by Travisty2520. 10 replies.
Page 1 of 1 (11 items)
Sort Posts: Previous Next
  • 07-11-2012 04:47 AM

    Help please-Solve: Number of days = (todays date - date initiated) ????

    I can build this argument in excel:    Column A = (C-B)    10 = (7/20/2012 - 7/10/2012)

    Column A is:  Number of days 

    Column B is:  Date Initiated

    Column C is: Todays Date 

     

    Can you please assist me with building this function in infopath

     

    thank you

  • 07-11-2012 06:24 AM In reply to

    Re: Help please-Solve: Number of days = (todays date - date initiated) ????

    Hi,

    Certain math, string and financial functions that are available in Excel are unfortunately not available in InfoPath. We resort to qRules when calculating date differences such as the one in your example above. Of course, custom code could also be used.

    Good luck!

    Ernesto Machado
    Qdabra® Software/ InfoPathDev.com
    The InfoPath Experts – Streamline data gathering to turn process into knowledge.™


  • 07-11-2012 12:41 PM In reply to

    Re: Help please-Solve: Number of days = (todays date - date initiated) ????

    Appreciate your help

    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!

    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.

  • 03-03-2013 02:36 PM In reply to

    Re: Help please-Solve: Number of days = (todays date - date initiated) ????

    I have got a different scenario - I would like to point everything to 31/12/<year+1>. Example: if I select 03/04/2013, I would like the next date to return 31/12/2014.

    Any kind souls like to throw in suggestion

  • 09-18-2013 01:29 PM In reply to

    Re: Help please-Solve: Number of days = (todays date - date initiated) ????

    This works great, but how can one remove Saturday's and Sunday's from the calculations?  Also, are there any tricks to including bank calendar holidays?

     

    Jason

  • 03-26-2014 01:44 PM In reply to

    • Judyy
    • Not Ranked
    • Joined on 03-25-2014
    • Posts 1

    Re: Help please-Solve: Number of days = (todays date - date initiated) ????

    Will this solution work for InfoPath 2010? I have tried it with no luck :(
    Filed under:
  • 04-11-2014 12:12 AM In reply to

    Re: Help please-Solve: Number of days = (todays date - date initiated) ????

    Hi, when using this formula to calculate difference between dates, example 01/03/2013 to 03/03/2014 formula calculates 2 days, acctually difference is + days.

    Can you please advice where add +1 day in the formula or to change the logic of calculation?

    Thank you

  • 07-12-2015 06:52 PM In reply to

    Re: Help please-Solve: Number of days = (todays date - date initiated) ????

    Thanks you. I am not a coder and this works perfrectly for me!!!
  • 08-14-2015 07:21 AM In reply to

    Re: Help please-Solve: Number of days = (todays date - date initiated) ????

     Hi,

    This code is working well until I pick dates that are in two different months. When I pick start date = 2015-08-01 and end date = 2015-09-05, it tells me that there are 4 days separating these dates while in fact there are 34. Any suggestions as how to fix this problem?

    Thanks

  • 05-31-2018 10:29 AM In reply to

    Re: Help please-Solve: Number of days = (todays date - date initiated) ????

    I utilize a separate SharePoint list to help calculate the number of days between two dates in Infopath. This is so I can account for leap years and have the ability to just count work days, not all days. I update this list with new data once a year.

    Here is the Excel file source for the list containing 2018-2020 data: https://1drv.ms/x/s!ApLhBloaS1wVgsUOMRrRfbekFftY9Q

    Steps:

    1. Import the first worksheet of the above Excel file as a new list in SharePoint.
    2. Add a receive data connection to this list from your InfoPath form.
    3. For the first date, create a action to convert the date to a number in YYYYMMDD format. Assuming the date is stored as DateTime, you can use this formula:  floor(number(translate(substring-before(../my:endDate, "T"), "-", "")))
    4. Query the list for the number value of the first date. Store this number in a field (column) in your form. (This field does not need to show in your form.)
    5. Repeat steps 3 & 4for the second date.
    6. Subtract the first date number from the 2nd, store this in a third column.


    Note: The Excel file uses the formula "NETWORKDAYS" and includes columns for weekdays, weekdays minus US Federal holidays, and weekdays minus NYSE holidays. Now you can get the number of work days between two dates using one of these columns. If you live outside the US, you could add a column to the Excel for other holidays, such as UK bank holidays.

    Dan Murphy
  • 07-30-2018 07:57 AM In reply to

    Re: Help please-Solve: Number of days = (todays date - date initiated) ????

     Hello,

     I am using two Date/Time fields to mark the start and end of a brake in out IT. I want the rules formulae to work out the difference between them as a mean time to repair for reporting currently using an spreadsheet but feel this is more progressive and can then add in other functions off this.

Page 1 of 1 (11 items)
Copyright © 2003-2018 Qdabra Software. All rights reserved.
View our Terms of Use.