Map dates
Map a date question that has time elements to a read-only question.
Rule description: Use this rule to map DateTime2 in form2 onto DateTime1 in form1.
Rule expression
return getDateDMYFormat(dt2,"HH:mm");
Definitions
- getDateDMYFormat( )
- Returns a date or datetime in DD-Mon-YYYY format, including time elements if applicable.
- dt2
-
Corresponds to DateTime2 in rule description.
-
"HH:mm"
- Time format passed as a parameter for the
getDateDMYFormat()
helper function to define the output format of the time elements present.
Return value
- Date
-
Returns a date (including a partial date) in DD-Mon-YYYY HH:MM format by passing in:
- DD (day value): uses the JavaScript getDate( ) method passed into the pad2( ) function that ensures a leading zero is appended where required to ensure a two-digit numerical value is returned.
- - (separator): appends a hyphen "-" in string format.
- Mon: uses the JavaScript getMonth( ) method to return
a number that represents the month of the date (0 to
11) into a new variable
mnth
. This variable is used as an index for thefullmnth
array to return the month as a three-letter abbreviation. For example,Apr
. - - (separator): appends a hyphen "-" in string format.
- YYYY (Year value): uses the
JavaScript
getFullYear()
method. - appends a blank space " ".
- HH (hours value): uses the JavaScript getHours( ) method passed into the pad2( ) function that ensures a leading zero is appended where required to ensure a two-digit numerical value is returned.
- : (time elements separator): appends a colon ":" in string format.
- MM (minutes value): uses the JavaScript getMinutes( ) method passed into the pad2( ) function that ensures a leading zero is appended where required to ensure a two-digit numerical value is returned.
Note:
+" "+pad2(dt2.getHours())+":"+pad2(dt2.getMinutes())
is used
to add time component. Exclude from the return statement if the date item does
not include a time element.
Verification steps
- Using a subject for testing, go to the given visit and form
containing the date item to map, in this example the date time in form
2 <
dt2
> to be mapped into date time in form 1. - Update the form item
dt2
as in the following table and verify the result mapped to the target item in form 1 is as listed:dt2
Mapped value in form 1 '30-Oct-2021 01:23' '30-Oct-2021 01:23' '31-Oct-2021 23:59' '31-Oct-2021 23:59' Null
Null
Note:
Repeat the above steps if the form is present in multiple visits.
Other examples
Example 4-16 Map date of visit in status form as visit date
return getDateDMYFormat(date);
Parent topic: Date comparisons