How to: |
Available Languages: reporting, Maintain
The HADD function increments a date-time value by a given number of units.
HADD(datetime, 'component', increment, length, output)
where:
Date-time
Is the date-time value to be incremented, the name of a date-time field that contains the value, or an expression that returns the value.
Alphanumeric
Is the name of the component to be incremented enclosed in single quotation marks. For a list of valid components, see Arguments for Use With Date and Time Functions.
Note: WEEKDAY is not a valid component for HADD.
Integer
Is the number of units (positive or negative) by which to increment the component, the name of a numeric field that contains the value, or an expression that returns the value.
Integer
Is the number of characters returned. Valid values are:
8 indicates a date-time value that includes one to three decimal digits (milliseconds).
10 indicates a date-time value that includes four to six decimal digits (microseconds).
12 indicates a date-time value that includes seven to nine decimal digits (nanoseconds).
Date-time
Is the field that contains the result, or the format of the output value enclosed in single quotation marks. This field must be in date-time format (data type H).
HADD adds two months to each value in TRANSDATE and stores the result in ADD_MONTH. If necessary, the day is adjusted so that it is valid for the resulting month.
TABLE FILE VIDEOTR2
PRINT CUSTID TRANSDATE AS 'DATE-TIME' AND COMPUTE
ADD_MONTH/HYYMDS = HADD(TRANSDATE, 'MONTH', 2, 8, 'HYYMDS');
WHERE DATE EQ 2000;
END
The output is:
CUSTID DATE-TIME ADD_MONTH ------ --------- --------- 1237 2000/02/05 03:30 2000/04/05 03:30:00 1118 2000/06/26 05:45 2000/08/26 05:45:00
HADD adds two months to the DT1 field:
MAINTAIN FILE DATETIME
FOR 1 NEXT ID DT1 INTO DTSTK
COMPUTE
NEW_DATE/HYYMDS = HADD(DTSTK.DT1, 'MONTH', 2,10, NEW_DATE);
TYPE "DT1 IS: <DTSTK(1).DT1 "
TYPE "NEW_DATE IS: <NEW_DATE "
The result is:
DT1 IS: 2000/1/1 02:57:25 NEW_DATE IS: 2000/3/1 02:57:25 TRANSACTIONS: COMMITS = 1 ROLLBACKS = 0 SEGMENTS : INCLUDED = 0 UPDATED = 0 DELETED = 0
WebFOCUS |