I have three editable date/time fields which the first two is (field1 and field2), style: Calendar/time control. Both of them are showing the time: hour and minutes, eg: 15:51.
The third field also (editable) which I want to show the difference between field1 and field2.
Eg: If field1 is 14:41 and field2 is 14:30, then field3 = 00:11. I've tried field1-field2 but isn't working. The form has automatic refresh fields property. Thanks!
I wrote this code, much easier...
Fields 'StartTime' and 'EndTime': Type Date/Time, use Calendar/Time control, set it to only display time. Check the property "Run Exiting/OnChange events after value changes". The Exiting event should look like this:
Field 'Duration': Editable text field, but hidden.
Field 'dspDuration': Computed for display text field. Value is just "Duration" (no quotes).
Then add the following code to the forms Global section:
That's it. Easy, isn't it? If you want to modify the output (duration), you can easily do that, perhaps change it into minutes by diving it by 60.
Your third field needs to be computed, not editable.
If it HAS to be editable for some reason, and you want it to update when the other two fields are changed, do this:
Create a new field and make it computed-for-display and hidden. Give it a formula like this
Phil
Make sure you are getting the difference between two date time fields. If you need to, you can use the @TextToTime formula to convert text to a datetime type.
Then just subtract the first date from the second date and you'll get the difference in seconds.
Then divide that by 60 to get the difference in minutes.