Add days to a date

Step 1: Insert a date picker control that displays the current date by default

The date picker control is designed explicitly for storing dates. In order to add a set number of days to a date that users enter into a control, you must first add a date picker control to your form template. You can then create a formula that uses the today function to display the current date in that control by default.
  1. On the form template, click where you want to insert the data picker.
  2. If the Controls task pane is not visible, click More Controls on the Insert menu, or press ALT+I, C.
  1. Under Insert controls in the Controls task pane, click Date Picker.
  2. In your form template, type Today's Date in front of the date picker control that you just inserted.
  3. Double-click the date picker control that you just inserted.
  4. Click the Data tab.
  1. In the Field name box, type a name for the field.
 Tip   It is a good idea to use a name that describes the contents of the field. A descriptive name makes the form template easier to understand for you or anyone modifying the form template. For example, you might type dteToday.
  1. Click Apply.
  2. Click Insert Formula Button image.
  1. Click Insert Function in the Insert Formula dialog box.
  2. Under Categories in the Insert function dialog box, click Date and Time, and then, under Functions, click today.

Step 2: Insert a text box that contains the addDays function

After you add the date picker control and create the formula that uses the today function, you can add a text box to your form template and create a formula that uses the addDays function.
  1. On the form template, click where you want to insert the text box.
  2. If the Controls task pane is not visible, click More Controls on the Insert menu, or press ALT+I, C.
  1. Under Insert controls in the Controls task pane, click Text Box.
  2. In your form template, type 30 Days Later in front of the text box control that you just inserted.
  3. Double-click the text box that you just inserted.
  4. Click the Data tab.
  1. In the Field name box, type a name for the field, and then click Apply.
 Tip   It is a good idea to use a name that describes the contents of the field. A descriptive name makes the form template easier to understand for you or anyone modifying the form template. For example, you might type txtAdd30Days.
  1. Click Insert Formula Button image.
  1. Click Insert Function in the Insert Formula dialog box.
  2. Under Categories in the Insert function dialog box, click Date and Time, and then under Functions, click addDays.
  3. Click OK.
  4. In the Formula box, double-click the first instance of double click to insert field.
  5. In the Select a Field or Group dialog box, click dteToday, and then click OK.
  6. Click the second instance of double click to insert field, press DELETE, and then type the number of days that you want to add to the current date. For example, if you wanted to add 30 days to today's date, you would type 30.
  7. To test that your formula is entered correctly, click Verify Formula.
My formula contains errors
Click Show Details in the Microsoft Office InfoPath dialog box to see the errors in the formula. The following are some suggestions for resolving these errors:
  • If you are using a function in your formula, verify that you are using the correct arguments for the function. Some functions require fields or groups while other functions require specified values as arguments. Find links to more information about functions in the See also section.
  • Delete and retype your formula to make sure that it is correctly typed.
Click Show Details in the Microsoft Office InfoPath dialog box to see the errors in the formula. The following are some suggestions for resolving these errors:
  • If you are using a function in your formula, verify that you are using the correct arguments for the function. Some functions require fields or groups while other functions require specified values as arguments. Find links to more information about functions in the See also section.
  • Delete and retype your formula to make sure that it is correctly typed.

Step 3: Change how the date is displayed in the text box

After you add the text box and create the formula to display the new date, you can format how the date is displayed in the text box.
  1. In the form template, double-click the text box.
  2. Click the Data tab.
  1. In the Data Type list, click Date (date), and then click Format.
  2. In the Display the date like this list, click the display style that you want.
 Note   Display styles that have an asterisk will update based on the user's system settings.
  1. To test your changes, click Preview on the Standard toolbar, or press CTRL+SHIFT+B.

Comments