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

How to:

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


Top of page

x
Syntax: How to Find the Number of Units Between Two Date-Time Values
HDIFF(end_timestamp, start_timestamp, component, output_format) 

where:

end_timestamp

Date-Time

Is the timestamp value to subtract from.

start_timestamp

Date-Time

Is the timestamp value to subtract.

component

Alphanumeric

Is the name of the component to be incremented. For a list of valid components, see Date and Time Components For Date and Date-Time Functions. If the component is a week, the WEEKFIRST parameter setting is used in the calculation.

output_format

Floating-point double precision



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

Assume that we have a date-time field DTCUR in H format, which is has a current date and time timestamp. To find the number of days from President's Day 2004 to today use the expression:

DIFDAY/I6 = HDIF(DTCUR, DT(2004/02/16), 'DAY', 'D6.0')

The function returns the number of days in double precision floating point format, then assigns it to DIFDAY as integer value. If today is March 31, 2004, the DIFDAY is assigned to 46.

If you wish to obtain results in seconds, use the expression

DIFSEC/I9 = HDIF(DTCUR, DT(2004 February 16), 'SECOND', 'D9.0')

which assigns 3801600 to DIFSEC. Note that the format 'D9.0' is used with HDIF. Using 'I9' for an output_format in HDIF is invalid.


iWay Software