DMY, MDY, YMD: Calculating the Difference Between Two Dates

How to:

Available Languages: reporting, Maintain

The DMY, MDY, and YMD functions calculate the difference between two dates in integer, alphanumeric, or packed format.


Top of page

x
Syntax: How to Calculate the Difference Between Two Dates
 function(begin, end)

where:

function

Is one of the following:

DMY calculates the difference between two dates in day-month-year format.

MDY calculates the difference between two dates in month-day-year format.

YMD calculates the difference between two dates in year-month-day format.

begin

I, P, or A format with date display options.

Is the beginning date, or the name of a field that contains the date.

end

I, P, or A format with date display options.

Is the end date, or the name of a field that contains the date.



Example: Calculating the Number of Days Between Two Dates

YMD calculates the number of days between the dates in HIRE_DATE and DAT_INC:

TABLE FILE EMPLOYEE
SUM HIRE_DATE FST.DAT_INC AS 'FIRST PAY,INCREASE' AND COMPUTE
DIFF/I4 = YMD(HIRE_DATE, FST.DAT_INC); AS 'DAYS,BETWEEN'
BY LAST_NAME BY FIRST_NAME
WHERE DEPARTMENT EQ 'MIS';
END

The output is:

LAST_NAME
FIRST_NAME
HIRE_DATE
FIRST PAY INCREASE 
DAYS  BETWEEN
 
BLACKWOOD
CROSS
GREENSPAN
JONES
MCCOY
SMITH
ROSEMARIE
BARBARA
MARY
DIANE
JOHN
MARY
82/04/01
81/11/02
82/04/01
82/05/01
81/07/01
81/07/01
82/04/01
82/04/09
82/06/11
82/06/01
82/01/01
82/01/01
0
158
71
31
184
184
 

WebFOCUS