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.
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.
Use a Data Validation rule with a condition to check whether the start date is less than the end date.
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:
- In InfoPath, create a new Blank form template.
- Add two Date Picker controls to the InfoPath form template and name them startDate and endDate.
- Double-click startDate to open its Properties dialog box.
- On the Date Picker Properties dialog box, click Data Validation.
- On the Data Validation (startDate) dialog box, click Add.
- 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.
- 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.
- 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.
- On the Select a Field or Group dialog box, select endDate, and click OK.
- 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.
- Click OK to close all dialog boxes.
- 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.
Related InfoPath Articles:
- InfoPath 2010 date and time picker control basics
- Calculate the difference between two date picker controls in InfoPath using rules and formulas - no code!
- InfoPath Basics: 3 Ways to validate data in InfoPath
- Forcing users to select a particular day of the week from a date picker using rules and formulas
- How to extract the month name from a date picker in InfoPath
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. 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.