Calculations of Time within InfoPath

A

aspear

I have field in which military time will be entered... I need assistance with
being able to calculate total time by adding values and substracting values
if I need the difference in the time...

Output field I need to be converted in to a decimal number instead of time....

I have look at SEVERAL BLOGS if anyone has that xpath for the conversion
please send it...

Thanks,
AS
 
G

Greg Collins

This should give you something to go on. It adds a repeating table of time
values and shows you the number of seconds. You can recalculate once you
have that value:

sum(xdMath:Eval(my:Table/my:Row, "(substring(my:TimeField, 1, 2) * 3600 +
substring(my:TimeField, 4, 2) * 60 + substring(my:TimeField, 7, 2))"))
 
A

aspear

Once you get the values to add/substract the times and produce actual time
..... will this string return the decimal value that I need...

This is for a Travel Comp Request:
Begin Time 1615
End Time 1845
Total Time ????

I need that Total Time > HH MM right now I am just getting it to 230 which
I actually need to say 2.5 hrs of Travel Comp.
 
G

Greg Collins

I've posted an article that gets into more detail about what I was talking
about. It can be found here: http://www.braintrove.com/article/73

Basically what you are trying to do can be done in a very similar fashion to
what I describe in the above article. You need to convert each time into
seconds, subtract the first from the second, then display the restults in
hours.

In your case you have XML time values of "16:15:00" and "18:45:00"

This is the same as:
Begin = 16 * 3600 + 15 * 60 + 0 = 58500 seconds
End = 18 * 3600 + 45 * 60 + 0 = 67500 seconds

Now subtract: 67500 - 58500 = 9000 seconds.

Convert to hours: 9000 / 3600 = 2.5 hours

Take a look at my article, above, and then review again what I just
described here and you should be able to figure out how to make it work for
your needs.
 
A

aspear

Thanks so much will do....

Can all that be done within the InfoPath form itself....or do I need to make
adjustments/changes to the XML file itself...

I was hoping to do it within the InfoPath form setting the Default values
for a few fields within the form by formatting them to convert.....However I
am not extremely familiar with all the commands/functions ....

Thanks,
 
G

Greg Collins

Unless you are doing something unusual, you should be able to do it all in
the form itself.
 
Joined
Sep 27, 2017
Messages
1
Reaction score
0
Hi greg,

when i'm trying to calculate the below sceanrio in spList infopath form

Start Time 10:00:00 Am End Time : 06:00:00 Pm

two text boxes with
upload_2017-9-27_15-3-50.png


how to convert where to write the calculation

10*3600+0+0 =36000
6*3600+0+0 =21600
total 1440 sec


while converting NaN in text box could you please explain me in detail
Thank you
in advance





I've posted an article that gets into more detail about what I was talking
about. It can be found here: http://www.braintrove.com/article/73

Basically what you are trying to do can be done in a very similar fashion to
what I describe in the above article. You need to convert each time into
seconds, subtract the first from the second, then display the restults in
hours.

In your case you have XML time values of "16:15:00" and "18:45:00"

This is the same as:
Begin = 16 * 3600 + 15 * 60 + 0 = 58500 seconds
End = 18 * 3600 + 45 * 60 + 0 = 67500 seconds

Now subtract: 67500 - 58500 = 9000 seconds.

Convert to hours: 9000 / 3600 = 2.5 hours

Take a look at my article, above, and then review again what I just
described here and you should be able to figure out how to make it work for
your needs.

--
Greg Collins
Microsoft MVP
Visit Braintrove at http://www.braintrove.com
Visit InfoPathDev at http://www.infopathdev.com
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top