How to check whether a start date falls before an end date in InfoPath

This article shows you how to use data validation rules in InfoPath to compare two dates and check whether one date falls before another.

ADVERTISEMENTS

Problem

You have two InfoPath date picker controls. One date picker contains a start date and the other date picker contains an end date. You want to use InfoPath validation rules to check whether the start date falls before the end date.

Solution

Use a Data Validation rule with a condition to check whether the start date is less than the end date.

Discussion

As discussed in Date and time basics in Microsoft Office InfoPath, InfoPath dates are represented internally in the following format: YYYY-MM-DDThh:mm:ss.

The advantage of this format is that it's perfect for sorting and comparing. For example, 2008-12-01 will always be greater than 2008-02-29. And when you sort these two dates, 2008-02-29 will always come before 2008-12-01.

So this format allows you to use is less than and is greater than comparisons in conditions in rules in InfoPath to check whether one date falls before another.

You can accomplish this functionality as follows:

  1. In InfoPath, create a new Blank form template.
  2. Add two Date Picker controls to the InfoPath form template and name them startDate and endDate.
  3. Double-click startDate to open its Properties dialog box.
  4. On the Date Picker Properties dialog box, click Data Validation.
  5. On the Data Validation (startDate) dialog box, click Add.
  6. On the Data Validation (startDate) dialog box, select startDate from the first drop-down list box, select is not blank from the second drop-down list box, and click And.
  7. On the Data Validation (startDate) dialog box, select endDate from the first drop-down list box, select is not blank from the second drop-down list box, and click And.
  8. On the Data Validation (startDate) dialog box, select startDate from the first drop-down list box, select is greater than from the second drop-down list box, and choose Select a field or group from the third drop-down list box.
  9. On the Select a Field or Group dialog box, select endDate, and click OK.
  10. On the Data Validation (startDate) dialog box, type an error message (e.g. Start date must be before end date) in the ScreenTip and Message text boxes, and click OK.
  11. Click OK to close all dialog boxes.
  12. Repeat steps 3 through 11 for the endDate date picker.

You should now have a fully functional form so that when you select a date from any of the two date pickers and the start date does not fall before the end date, the InfoPath data validation rule will be triggered and display a red border around the two date fields.

 
 Subscribe for updates via RSS or Email

Copyright: This article may not be used on web sites (whether personal or otherwise), copied, disseminated, altered, printed, published, broadcasted, or reproduced in any way without an expressed written consent of S.Y.M. Wong-A-Ton. The techniques demonstrated in this article may be used within any Microsoft InfoPath project. This article is provided without any warranties. Copyright for this article is non-transferrable and remains with the author, S.Y.M. Wong-A-Ton.

InfoPath 2013 Cookbook: 121 Codeless Recipes for Beginners
InfoPath 2013 Cookbook 2: 121 Codeless Recipes for SharePoint 2013
InfoPath 2010 Cookbook: 101 Codeless Recipes for Beginners
InfoPath 2010 Cookbook 2: 101 Codeless Recipes for SharePoint 2010
InfoPath 2010 Cookbook 3: 101 Code Recipes for C# Developers
InfoPath 2010 Cookbook 5: Integrating InfoPath with Excel and Excel Services


Related InfoPath Articles:

ADVERTISEMENTS

InfoPath 2013 Cookbook: 121 Codeless Recipes for Beginners

InfoPath 2013 Cookbook 2: 121 Codeless Recipes for SharePoint 2013

InfoPath 2010 Cookbook: 101 Codeless Recipes for Beginners

InfoPath 2010 Cookbook 2: 101 Codeless Recipes for SharePoint 2010

InfoPath 2010 Cookbook 3: 101 Code Recipes for C# Developers

InfoPath 2010 Cookbook 4: 101 Code Recipes for VB Developers

InfoPath 2010 Cookbook 5: Integrating InfoPath with Excel and Excel Services