User Tools

Site Tools


userdocs:redcap_usage:base:save_time_on_form

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

userdocs:redcap_usage:base:save_time_on_form [2026/03/27 15:36] – created babbagejuserdocs:redcap_usage:base:save_time_on_form [2026/03/27 15:53] (current) babbagej
Line 1: Line 1:
 ====== Save time on form ====== ====== Save time on form ======
  
-You can automatically save the time spent on a form using two variables and some of the built in action tags.+You can automatically capture how long a user spends on a form by using two timestamp variables along with builtin 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 ====
  
-The first variable [form_load_ts] stores the time of the first load of an instrument.  If multiple forms need to have timing, each will need to have its own version of both of these variables. 
-This variable needs the following action tags: 
 <code> <code>
 @NOW-SERVER @READONLY @NOW-SERVER @READONLY
 </code>  </code> 
  
 +==== 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 ====
  
-The second variable [form_save_ts] stores the time of first save of an instrument.  Note that the calculation uses the form complete status of the form that it lives on.  This can be used to prevent a save time until the form is complete.  This is most often useful on a survey that will not be complete until all required fields are specified.  
 <code> <code>
-@CALCDATE(if(([form_1_complete] >= 0 and [form_save_ts] = ''), 'now', [form_save_ts]), 0, 'd'+@CALCDATE( 
-</code>+if(([form_1_complete] >= 0 and [form_save_ts] = ''),  
 +   'now',  
 +   [form_save_ts]), 
 +0,'d'
 +</code>  
 + 
 +==== 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 
  
userdocs/redcap_usage/base/save_time_on_form.txt · Last modified: by babbagej

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki