HDIFF: Finding the Number of Units Between Two Date-Time Values

How to:

Reference:

The HDIFF function calculates the number of date or time component units between two date-time values.

Reference: Usage Notes for HDIFF

HDIFF does its subtraction differently from DATEDIF, which subtracts date components stored in date fields. The DATEDIF calculation looks for full years or full months. Therefore, subtracting the following two dates and requesting the number of months or years, results in 0:

DATE1 12/25/2014, DATE2 1/5/2015   

Performing the same calculation using HDIFF on date-time fields results in a value of 1 month or 1 year as, in this case, the month or year is first extracted from each date-time value, and then the subtraction occurs.

Syntax: How to Find the Number of Units Between Two Date-Time Values

HDIFF(end_dt, start_dt, 'component', output)

where:

end_dt

Date-time

Is the date-time value to subtract from.

start_dt

Date-time

Is the date-time value to subtract.

component

Alphanumeric

Is the name of the component to be used in the calculation, enclosed in single quotation marks. If the component is a week, the WEEKFIRST parameter setting is used in the calculation.

output

Floating-point double-precision

WebFOCUS

Feedback