Search
Web Braintrove
Site Navigation
Home
Products
Tags
Levels
Dates
Authors
5 MOST RECENT
Perform a Case-Insensitive String Comparison without Using Translate()
Force a Field Value to a Boolean Using Rules
Quickly Crop to a Shadow
Preview and Open Forms after Upgrading to Internet Explorer 8
Eliminate NaN and Infinity Errors in Calculations
5 MOST POPULAR
Pass Query String Parameters to an ASP.NET Xml Control
Access a Method in a Master Page with Code-Behind
Prevent Namespace Prefixes from Being Copied to the Output
Create Groups in a Drop-Down List Box
Change the Default Action of the Power Button on the Windows Vista Start Menu
5 MOST FORGOTTEN
Install Windows 7 Beta onto a Virtual Machine
Convert Between Time and Decimal
Configure Lab Color Mode Defaults for Braintrove Articles
Permanently Change the Default Styles for New Word Documents
Use the Eyedropper Tool to Pick a Color From Anywhere
Microsoft MVP
This article has been viewed 231 times.

Sum Repeating Time Values

Written by Gregory Scot Collins
Tuesday, 14 April 2009, 2:31 PM
This article has been tested to work with the following products and versions. No guarantee of compatibility, with or without modification, is offered for products or versions other than those listed.
If you have a need to add up time values in an InfoPath repeating table or section, you can use the eval() function to accomplish your task.

The eval() function

eval() takes two arguments and returns a node-set containing the results of the expression in the second argument (which must exist in quotes) as applied to the node-set in the first argument.

Convert time to seconds

InfoPath stores time in the XML format of HH:MM:SS (hours, colon-separator, minutes, colon-separator, seconds). In this example, we will convert each time value to seconds and get the sum. Once we've obtained the sum in seconds, we can then display the number of seconds, or divide out into minutes or whatever.
To convert a time value into seconds, we must individually select the hours, minutes and seconds. Hours are converted to seconds when multiplied by 3600 and minutes are converted to seconds when multiplied by 60.
To get each portion of an XML time value, we will use the substring() function. substring() is 1-based, meaning the first character is found at position 1.

Perform the sum

With a DOM structure of my:myFields/my:Table/my:Row/my:TimeField, you can use the expression shown in Listing 1 in an Expression Box or a default value formula to get the sum of time in seconds:
We included the filter [. != ''] to ensure that only fields with values are included in the evaluation. This prevents the expression from resulting in the 1.#QNAN error. However, you will still get this error if you have invalid or non-time values in your list.

Convert to minutes or hours

If you prefer to display the sum minutes, append the expression in Listing 1 with div 60, or div 3600 if you prefer hours.
Bookmark this Article
StumbleUpon  Stumble It!
Digg  Digg It!
del.icio.us  del.icio.us
List of Figures
Listing 1 - Obtaining a sum in seconds from a repeating list time values.
Article Tags
Great Deals
TigerDirect Exclusive Deals, Limited Time Offers, Act Now And Save!
Find all current special offers on Adobe products.
Try SugarSync Free!
Join WebHost4Life.com
TigerDirect
Computers4SURE (4SURE.com - An Office Depot Co.)
Copyright © 2006-2010 Braintrove. All rights reserved. Braintrove, braintrove.com, and the Braintrove logo are trademarks of Gregory Scot Collins in the United States and/or other countries. The names of actual companies and products mentioned herein may be the trademarks of their respective owners. Any rights not expressly granted herein are reserved.