Calculating a date - InfoPath Dev
in

InfoPath Dev

Calculating a date

Last post 04-11-2014 01:05 AM by magdalena.deleva. 10 replies.
Page 1 of 1 (11 items)
Sort Posts: Previous Next
  • 11-11-2005 02:02 AM

    Calculating a date

    Hi erveryboy,

    does anybodyknow how to calculate dates without scripting or coding?

    I want do add a number (of days, e.g.) to the actual date (TODAY())? Any ideas?

    brgd
    Jan
  • 12-02-2005 08:28 PM In reply to

    Unfortunately date calculations are not possible without code in InfoPath 2003. The following entry on the InfoPath team blog discussed the code involved.

    http://blogs.msdn.com/infopath/archive/2005/01/25/360318.aspx

    Shiraz Cupala
    InfoPathDev
    Shiraz Cupala / Microsoft InfoPath MVP
    Qdabra® Software / Streamline data gathering to turn process into knowledge
  • 04-28-2008 09:24 AM In reply to

    Please would you be kind enough to show me how to do this and perhaps give me an example in nfopath 2007?

  • 04-28-2008 11:49 AM In reply to

    Hi Edward.

    In InfoPath 2007 you actually have a new function called adddays, if that is all you need. Otherwise you still must use DateDiff if you want to calculate the time between dates, etc.

    Searchign on datediff will give you some examples and script code.

  • 04-28-2008 02:01 PM In reply to

    I have followed this as below and hve attached my infopath file, would you be kind enough to tell me why this doesnt work? I just keep gtting a 0

     

    Calculating date differences in InfoPath using rules and formulas - no code!by S.Y.M. Wong-A-Ton
    Level:  ProblemYou have an InfoPath form with two date picker fields and would like to calculate the difference between the two date fields without writing code.SolutionUse rules, conditions, and the number(), floor(), and substring() functions in formulas to calculate the difference between two date fields in InfoPath. DiscussionYou can accomplish this functionality as follows:
    1. Design an InfoPath form 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 should resemble the following figure:


      Figure 2. The Main data source of the 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
    1. 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
    2. 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
    1. 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
    2. 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 as shown in the following figure.


    Figure 3. The InfoPath form in Internet Explorer.
  • 12-23-2008 08:24 AM In reply to

    Is there a way to substring the now() function to get just the time?

  • 12-23-2008 08:42 AM In reply to

    Sure.

    If you put the now function in an expression box and look at it you can see a couple options.

     I typically use the substring-after and then use the "T" since that seperates the date from the time.

    substring-after(now(), "T")

    You could break it down farther to eliminate the seconds if you wanted by just having the first five characters or whatever.

  • 12-23-2008 09:28 AM In reply to

    That is what I had original done but it is saying there is an error .. please see below             concat("CCSBO - ", max(@ID) + 1001, " - ", substring-after(now(), "T") What am I doing wrong?
  • 12-23-2008 07:12 PM In reply to

    You appear to be missing a trailing right-parens: 

    concat("CCSBO - ", max(@ID) + 1001, " - ", substring-after(now(), "T"))

     

  • 12-30-2008 10:18 AM In reply to

    Codeless solution looks nice. Although looking at the code I wasn't been able to figure out if leap years were taken into account. So I had no choice but create somthing by myself.

    http://alecpojidaev.wordpress.com/2008/12/30/infopath-codeless-programming-walkthrough-2/

    web-based forms: OK

    IP 2003: not OK

  • 04-11-2014 01:05 AM In reply to

    Hi Clay,

    can you advise how to calculate difference between days including start date and end date? Example, start date 01/03/2014 end date 03/03/2014. Number of days should be 3.

     With this solution, difference days is 2.

    Thank you very much.

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