Adding a date field and a number field to calculate a new date? - InfoPath Dev
in

InfoPath Dev

Use our Google Custom Search for best site search results.

Adding a date field and a number field to calculate a new date?

Last post 03-30-2017 08:09 AM by ChristinaGateley. 5 replies.
Page 1 of 1 (6 items)
Sort Posts: Previous Next
  • 03-28-2017 02:11 AM

    Adding a date field and a number field to calculate a new date?

    Hi, I hope someone can help.

     

    In my form I have a date field and a number field (this number field represents a year, so if the value is 1 then it equals 1 year).

    I want to add these two fields to give me a new date.  I've tried but I just get a return value of NaN, as you'd expect.

    Please can someone help me with the calculation so I get a date value?

     

    If it helps, the calculation I have tried so far is:  ../my:field8 + (../my:field22 * 365) 

      

    Thank you. 

  • 03-28-2017 07:43 AM In reply to

    Re: Adding a date field and a number field to calculate a new date?

    You'll need to use the addDays() function in InfoPath. So in your formula editor, click the button for inserting a function, and find the addDays() function. The first parameter is your date field and the second is the number you want to add. So maybe xdDate:AddDays(../my:field8, (../my:field22 * 365))
    Hilary Stoupa

  • 03-29-2017 02:26 AM In reply to

    Re: Adding a date field and a number field to calculate a new date?

    Hi Hilary, The formula worked great; thank you. My only issue now is that whilst the month and year is calculated correctly, the day is not. It appears to subtract day. For instance, I have a document with a 5 year review period from today, so I'd expect the review by date to be 29/03/22, but it returns as 28/03/22. Do you perhaps know why it does this and what I can do to solve it? Best wishes, Christina.
  • 03-29-2017 03:59 AM In reply to

    Re: Adding a date field and a number field to calculate a new date?

     P.S. this doesn't happen for every entry so could this be dependent on the time that the document was created/published?

    Thank you. 

  • 03-29-2017 07:34 AM In reply to

    Re: Adding a date field and a number field to calculate a new date?

    Do you suppose leap year is coming into play here at all? If you really just want to add years, let me know - you could do that with a substring formula, because incrementing the year is simple. XML dates are stored in yyyy-MM-dd format, so you can use substring-before to get just the year and increment it.... something like: concat(substring-before(fieldWithDate, "-") + fieldWithNumberOfYears, "-", substring-after(fieldWithDate, "-"))
    Hilary Stoupa

  • 03-30-2017 08:09 AM In reply to

    Re: Adding a date field and a number field to calculate a new date?

    I hadn't thought about it, but you could be right!

    I tried the alternative and that worked great also.

    Thank you very much for your help and time :) 

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