Date and time basics in Microsoft Office InfoPath
Understand how Microsoft Office InfoPath uses dates to be able to do your own date manipulations and calculations within InfoPath.
You want to filter data on the current month, display the date in a way that is not available in Microsoft Office InfoPath, or perform calculations with dates.
Use the fact that Microsoft Office InfoPath represents dates and times internally as YYYY-MM-DDThh:mm:ss to be able to filter, display, and perform calculations with dates and times within InfoPath.
InfoPath comes with 3 date/time data types:
- Date (date)
- Time (time)
- Date and Time (dateTime)
The following table lists the corresponding internal representations InfoPath uses for each data type:
|Data Type||Internal InfoPath Representation|
|Date and Time (dateTime)||YYYY-MM-DDThh:mm:ss|
InfoPath uses the format you set on a date/time field through the Properties dialog box of the field and the Format... button to display dates and times. InfoPath will show dates/times in any way you have indicated, like e.g. 9:46 P.M., 21:46, 2/19/2006, or 19-02-2006. Keep in mind that this is only a visual display. When InfoPath performs validation on date and time fields, it still uses its own internal date and time representations.
This is important to know when you want to write date and time values to fields using code. If for example
you set a field's data type to Date (date) and you
write 2006-02-19T13:00:23 to the field through code, you will get the following
To correct this error, change the field's data type to Date (date) and write 2006-02-19 to the field, or change the field's data type to Date and Time (dateTime) and write 2006-02-19T13:00:23 to the field.
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.
Related InfoPath Articles:
- Calculating time differences in InfoPath without custom code
- Calculating a person's age given a date of birth using rules and formulas in InfoPath
- InfoPath 2010 date and time picker control basics
- InfoPath 2010 date picker default value
- Extracting day, month, and year numbers from dates in InfoPath