locked
Add days to date field RRS feed

  • Question

  • Using Infopath I am trying to add to fields together one is a date field and another filed (Cycle) that lists the number of years until the next date occurs.

    I tried using a calculated date field with the formula Datefield + Cycle*365

    I get an error NAN.  What am I doing wrong?

    Friday, March 25, 2011 5:11 PM

Answers

  • Put a rule on your cycle field.  Make the rule action "set a field's value".  For the field to set choose DateField.  For the value click fx.  Click "insert function" > Choose "addDays".  For the first field (where it says click to insert a field) choose Datefield.  For the second field choose Cycle.  Then add you're *365 and put them in parenthesis, so it should look like:

    addDays(Datefield, (Cycle*365))

    Click ok and test it.  This will only update when the cycle field is updated.  You cannot put this formula on the Datefield itself because you will cause an infinite loop, which means it will continually add these years until it errors.

    Also please note that using this method it will add the exact number of days that is the result of the cycle value multiplied by 365.  It will not just add 4 years into the year.  So a March 31, 2011 with a cycle value of 4 will become March 30, 2015.

    • Marked as answer by David HM Monday, April 4, 2011 1:18 AM
    Friday, March 25, 2011 8:11 PM

All replies

  • Put a rule on your cycle field.  Make the rule action "set a field's value".  For the field to set choose DateField.  For the value click fx.  Click "insert function" > Choose "addDays".  For the first field (where it says click to insert a field) choose Datefield.  For the second field choose Cycle.  Then add you're *365 and put them in parenthesis, so it should look like:

    addDays(Datefield, (Cycle*365))

    Click ok and test it.  This will only update when the cycle field is updated.  You cannot put this formula on the Datefield itself because you will cause an infinite loop, which means it will continually add these years until it errors.

    Also please note that using this method it will add the exact number of days that is the result of the cycle value multiplied by 365.  It will not just add 4 years into the year.  So a March 31, 2011 with a cycle value of 4 will become March 30, 2015.

    • Marked as answer by David HM Monday, April 4, 2011 1:18 AM
    Friday, March 25, 2011 8:11 PM
  • I know this is several years ago but did you ever get this figured out?  I have a form I am creating where the user has 6 different options (1-6 years), and I want to add the selected years to a date and calculate the new date.  Any help is appreciated.
    Tuesday, November 24, 2015 9:32 PM
  • Hi Daniel,

    The answer is in my reply above.  For your case - in the formula, put the year selection field in place of "Cycle".  I'm assuming that the field that they select is a numeric value of 1, 2, 3, 4, 5, 6 (not actual years) - is this correct?

    Melissa

    Wednesday, November 25, 2015 2:06 PM