DA Functions: Converting a Legacy Date to an Integer
 How to:Convert a Date to an Integer

Available Languages: reporting, Maintain

The DA functions convert a legacy date to the number of days between it and a base date (December 31, 1899). By converting a date to the number of days, you can add and subtract dates and calculate the intervals between them, or you can add to or subtract numbers from the dates to get new dates.

You can convert the result back to a date using the DT functions discussed in

There are six DA functions; each one accepts a date in a different format.

 Top of page
Syntax: How to Convert a Date to an Integer
`						function(indate, output)`

where:

function

Is one of the following:

DADMY converts a date in day-month-year format.

DADYM converts a date in day-year-month format.

DAMDY converts a date in month-day-year format.

DAMYD converts a date in month-year-day format.

DAYDM converts a date in year-day-month format.

DAYMD converts a date in year-month-day format.

indate

I6xxx or P6xxx, where xxx corresponds to the function DAxxx you are using.

Is the legacy date to be converted, or the name of a field that contains the date. The date is truncated to an integer before conversion. If indate is a numeric literal, enter only the last two digits of the year; the function assumes the century component. If the date is invalid, the function returns a 0.

output

Integer

Is the name of the field that contains the result, or the format of the output value enclosed in single quotation marks. The format of the date returned depends on the function.

 Top of page
Example: Converting Dates and Calculating the Difference Between Them

DAYMD converts the DAT_INC and HIRE_DATE fields to the number of days since December 31, 1899, and the smaller number is then subtracted from the larger number:

```TABLE FILE EMPLOYEE
PRINT DAT_INC AS 'RAISE DATE' AND COMPUTE
DAYS_HIRED/I8 = DAYMD(DAT_INC, 'I8') - DAYMD(HIRE_DATE, 'I8');
BY LAST_NAME BY FIRST_NAME
IF DAYS_HIRED NE 0
WHERE DEPARTMENT EQ 'PRODUCTION';
END```

The output is:

```LAST_NAME     FIRST_NAME  RAISE DATE  DAYS_HIRED
---------     ----------  ----------  ----------
IRVING        JOAN          82/05/14         130
MCKNIGHT      ROGER         82/05/14         101
SMITH         RICHARD       82/05/14         130
STEVENS       ALFRED        82/01/01         578
81/01/01         213```
 WebFOCUS