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.

ADVERTISEMENTS

Problem

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.

Solution

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.

Discussion

InfoPath comes with 3 date/time data types:

  1. Date (date)
  2. Time (time)
  3. Date and Time (dateTime)

The following table lists the corresponding internal representations InfoPath uses for each data type:

Data Type Internal InfoPath Representation
Date (date) YYYY-MM-DD
Time (time) hh:mm:ss
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 validation error:
Date validation error in Microsoft Office InfoPath
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.

 
 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