Summary
This command calculates the difference between a “from date” and a “to date”. When partial dates are used, then the minimum difference between the dates is returned. It is essential to supply a unit to the command. The return value is the number of units that fit between the “from date” and the “to date”. When “from date” is after the “to date”, then a negative value is returned. The method attribute determines whether an integer or a floating point number is returned.
Attributes
- unit (required) – The date unit on which the command should operate
- method (optional) – The method to use when performing the calculation
- last (optional) – Indicates the last unit of time that will be used in the calculation (i.e. If last is set to ”hour”, the minute, second, and millisecond will be ignored when calculating the difference); useful for partial dates when you need to explicitly ignore unknown portions of the date
Available Values for the ‘Unit’ Attribute and ‘Last’ Attribute
- year
- month
- day
- hour
- minute
- second
- millisecond
Available Methods
- integer
- float
- default – Uses the Integer method for years and months and the float method for days, hours, minutes, seconds and milliseconds
Parameters
- from – The “from” value can either be a Date or PartialDate question, a Date or PartialDate object, or a string with the internal PartialDate format.
- to – The “to” value can either be a Date or PartialDate question, a Date or PartialDate object, or a string with the internal PartialDate format.
Example
<script scriptId="absVal"> <body> <s:alert> <s:expression> <s:or> <s:not> <s:isSet> <s:question> <s:question path=".hudt"/> </s:question> </s:isSet> </s:not> <s:not> <s:isSet> <s:question> <s:question path=".hutime"/> </s:question> </s:isSet> </s:not> <s:not> <s:isSet> <s:question> <s:question path=".fcon1dt"/> </s:question> </s:isSet> </s:not> <s:not> <s:isSet> <s:question> <s:question path=".fcon1time"/> </s:question> </s:isSet> </s:not> <s:lte> <s:abs> <s:dateDiff unit="minute" method="integer"> <s:from> <s:toDate> <s:concat> <s:toString> <s:datePath type="date" path=".hudt:value"/> <s:string value="MM/dd/yyyy"/> </s:toString> <s:string value=" " /> <s:toString> <s:datePath type="date" path=".hutime:value"/> <s:string value="HH:mm"/> </s:toString> </s:concat> <s:string value="MM/dd/yyyy HH:mm" /> </s:toDate> </s:from> <s:to> <s:toDate> <s:concat> <s:toString> <s:datePath type="date" path=".fcon1dt:value"/> <s:string value="MM/dd/yyyy"/> </s:toString> <s:string value=" " /> <s:toString> <s:datePath type="date" path=".fcon1time:value"/> <s:string value="HH:mm"/> </s:toString> </s:concat> <s:string value="MM/dd/yyyy HH:mm" /> </s:toDate> </s:to> </s:dateDiff> </s:abs> <s:number value="240"/> </s:lte> </s:or> </s:expression> <s:correction> <s:string value="optional"/> </s:correction> <s:text> <s:string value="The absolute difference between the 'Holter Monitor Hook-Up' and the 'First Contrast Injection' should be no more than 4 hours. Please verify."/> </s:text> </s:alert> </body> <target typeId="fcon1time" when="preprocess" shouldReconcile='true'/> <dependent path="/summary/ecgReport[n].hudt"/> <dependent path="/summary/ecgReport[n].hutime"/> <dependent path="/summary/ecgReport[n].fcon1dt"/> </script>
Note: If you are dealing with dates and times that cross over midnight (12 AM or 00:00), it is preferable to convert the dates and times to the Partial Date format in the script to ensure that the calculation is performed accurately. An example of this would be as follows:
<s:dateDiff method='integer' unit='minute' > <s:from> <s:toPartialDate> <s:concat> <s:toString> <s:datePath path='/demographics.dateA:value' type='date' /> <s:string value='dd-MMM-yyyy' /> </s:toString> <s:string value=' ' /> <s:toString> <s:datePath path='/demographics.timeA:value' type='date' /> <s:string value='HH:mm' /> </s:toString> </s:concat> <s:string value='dd-MMM-yyyy HH:mm' /> </s:toPartialDate> </s:from> <s:to> <s:toPartialDate> <s:concat> <s:toString> <s:datePath path='/demographics.dateB:value' type='date' /> <s:string value='dd-MMM-yyyy' /> </s:toString> <s:string value=' ' /> <s:toString> <s:datePath path='/demographics.timeB:value' type='date' /> <s:string value='HH:mm' /> </s:toString> </s:concat> <s:string value='dd-MMM-yyyy HH:mm' /> </s:toPartialDate> </s:to> </s:dateDiff>
Need more help?
Please visit the Fountayn Contact Information page.