====== Save time on form ======
You can automatically capture how long a user spends on a form by using two timestamp variables along with built‑in REDCap action tags. This approach works for both instruments and surveys.
If you want to track time on multiple forms, each form must have its **own pair of variables**.
===== Form Load Timestamp =====
==== Variable Name ====
[form_load_ts]
This variable records the time when the instrument is first loaded.
==== Required action tags ====
@NOW-SERVER @READONLY
==== What this does ====
* @NOW-SERVER sets the value to the current server time when the form initially loads.
* @READONLY prevents users from editing the timestamp.
* The value remains unchanged across page reloads or subsequent visits to the same form instance.
===== Form Save Timestamp =====
==== Variable Name ====
[form_save_ts]
This variable captures the time of the first save for the instrument. The calculation relies on the form’s completion status, which allows you to control// when// the timestamp is set.
This is particularly useful for surveys, where you don’t want to record a save time until all required fields are completed and the form is marked complete.
==== Calculation ====
@CALCDATE(
if(([form_1_complete] >= 0 and [form_save_ts] = ''),
'now',
[form_save_ts]),
0,'d')
==== What this does ====
* Checks whether the form has reached a valid completion state ([form_1_complete] >= 0)
* If the form is eligible and [form_save_ts] is blank, it records the current time
* Once set, the value does not update on subsequent saves
* @CALCDATE ensures the value is stored in proper date/time format
==== Note: ====
Make sure the calculation references the correct completion field (e.g., [demographics_complete]) for the instrument where this variable is defined.
===== Result =====
With both timestamps in place:
* You can calculate time spent on the form by subtracting [form_load_ts] from [form_save_ts]
* The method works for both instruments and surveys
* Users cannot modify the stored timestamps