`CLCDATDIF2      CALCULATE DATE DIFFERENCE 2            TAADATQ`
```
The  Calculate Date  Difference  2  command  determines the  number  of
years, months,  and days between 2 dates.   This calculation is used in
some  types of insurance.   The date  formats of the  From and To dates
may differ in format.   The two dates must  be valid and the From  date
must be less than or equal the To date.

A typical command would be:

DCL        &RTNYRS *DEC LEN(5 0)
DCL        &RTNMTHS *DEC LEN(3 0)
DCL        &RTNDAYS *DEC LEN(3 0)
.
CLCDATDIF2 FROMDATE('010809') TODATE('030710')
FROMFMT(*MDY)
RTNYRS(&RTNYRS) RTNMTHS(&RTNMTHS)
RTNDAYS(&RTNDAYS)

The values returned would be:

RTNYRS  = 1
RTNMTHS = 1
RTNDAYS = 30

The following are sample results:

CLCDATDIF2 may only  be used in a CL program.   The FROMDATE and TODATE
parameters may be variables.

From MMDDYYYY   To MMDDYYYY      Rtn years   Rtn months   Rtn days
-------------   -----------      ---------   ----------    -------

01012005       01122005           0           0           11
01012004       02022005           1           1            1
01012009       03072009           1           1           29
12311999       12251999          TAA9892 Error (From date is GT)

The algorithm used is:

**   The dates are converted to a common format.

**   The  From year is subtracted from the  To year and the result is
placed in the RTNYRS parameter.

**   The From month is compared to  the To month.  If the From  month
is greater,  12 is  added to  the To month  and 1  is subtracted
from  the RTNYRS parameter.   The From month  is then subtracted
from the  To month  and  the result  is  placed in  the  RTNMTHS
parameter.

**   The From  day is compared  to the To  day.  If  the From  day is
greater, the  number of days in  the From month is  added to the
To  day value  and 1 is  subtracted from  the RTNMTHS parameter.
The From day is then  subtracted from the To day and  the result
is placed in the RTNDAYS parameter.

Leap years and year 2000 are handled correctly.

Command parameters                                    *CMD
------------------

FROMDATE      The From date.   It must be a  valid date according to
the FROMFMT parameter.

TODATE        The  To date.   It must be  a valid  date according to
the TOFMT parameter.

FROMFMT       The format  of the  From date.   *JOB  is the  default
meaning  the  date is  in  the  format of  the  DATFMT
setting  of the  job.   Other values  include *SYSVAL,
*MDY, *DMY, *YMD,  *MDYY, *DMYY,  *YYMD, *JUL,  *CYMD,
*ISO, *USA, *EUR, and *JIS.

TOFMT         The format of  the To date.   *FROMFMT is  the default
meaning  the value  of  the FROMFMT  parameter.   *JOB
may  be specified  to mean the  date is  in the format
of the  DATFMT  setting  of  the job.    Other  values
include  *SYSVAL,  *MDY,  *DMY,  *YMD,  *MDYY,  *DMYY,
*YYMD, *JUL, *CYMD, *ISO, *USA, *EUR, and *JIS.

RTNYRS        The   difference   in  years.      See   the  previous
documentation for how the value is calculated.

RTNMTHS       The  difference   in  months.     See   the   previous
documentation for how the value is calculated.

RTNDAYS       The   difference   in   days.     See   the   previous
documentation for how the value is calculated.

Restrictions
------------

Because  the  command returns  values,  it may  only  be used  in  a CL
program.

Prerequisites
-------------

The following TAA Tools must be on your system:

CVTDAT2         Convert date 2
SNDESCMSG       Send escape message

Implementation
--------------

None, the tool is ready to use.

Objects used by the tool
------------------------

Object        Type    Attribute      Src member    Src file
------        ----    ---------      ----------    ----------