Calculate Elapsed Time

alexcharleswort
Tera Expert

This is a simple question, but I am truly atrocious with anything involving calculating date/times.

I have two date/time variables (u_start, u_end). What I want to have happen is to populate another variable (u_elapsed) on the form telling me how much time has elapsed.

I assume I would do an onSubmit client script that calculate (u_end - u_start), but I'm not sure how to write it the proper way and what sort of variable u_elapsed should be for it to populate correctly? String, integer, decimal?

Thanks in advance for your help!

1 ACCEPTED SOLUTION

Abhinay Erra
Giga Sage

Here you go. Elapsed time should be of duration type and here is how your code will look like. Put this script in the before business rule


Before insert and update


script:


current.u_elapsed.setDisplayValue(gs.dateDiff(current.u_start.getDisplayValue(),current.u_end.getDisplayValue(),false));


View solution in original post

3 REPLIES 3

Subhajit1
Giga Guru

u_elapsed can be a Date-Time variable.


You can use GlideAjax to send the u_start and u_end values to Server side, use the gs.dateDiff() method to calculate the difference and bring the difference value back to the Form through Return and set the value on u_elapsed.


You can refer to the following link for more information:-


Client Script Date/Time Functions


Abhinay Erra
Giga Sage

Here you go. Elapsed time should be of duration type and here is how your code will look like. Put this script in the before business rule


Before insert and update


script:


current.u_elapsed.setDisplayValue(gs.dateDiff(current.u_start.getDisplayValue(),current.u_end.getDisplayValue(),false));