Expand my Community achievements bar.

Total number of hours from date and time fields

Avatar

Former Community Member
Need a script that calculates total hours spent on a project using four fields which are as follows:

DATE FIELD 1=From Date (MM/DD/YYYY)

TIME FIELD 1=From Time (24 hour clock)

DATE FIELD 2=To Date (MM/DD/YYYY)

TIME FIELD 2=To Time (24 hour clock)



NUMERIC CALCULATION ONLY FIELD=Total time spent on job



ex. from 08/30/2007 2300 hrs to 08/31/2007 0600 hrs = 7 hours Total



Any ideas?
3 Replies

Avatar

Level 7
Yes, with LiveCycle Designer you can can use either FromCalc's "Time2Num()" function to get the number of milliseconds from the epoch date to the passed date time string, or use JavaScript's DateTime object to get the number of milliseconds from the epoch date. For both of these methods the format string for the date and time are very important in getting the correct value of the milliseconds from the epoch date.



Once one has the milliseconds from the epoch date for the start and end times, one need only compute the difference between the 2 values and and then convert then result back to days, hours, minutes, seconds, milliseconds as needed.

Avatar

Former Community Member
Based on 2 values how would I convert to days and hours.

Avatar

Former Community Member
Lbee1, Did you ever figure this out?



Thanks,

Scott