How to: |
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.
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.
Integer
Is the number of characters returned. Valid values are:
Date-time
The following example increments thirty months to some specific date-time in the past
HADD(DT(2001/09/11 08:54:34), 'MONTH', 30, 8, 'HYYMDS')
and returns the timestamp 2004/03/11 08:54:34.00.
Unix time (also known as Epoch time) defines an instant in time as the number of seconds that have elapsed since 00:00:00 Coordinated Universal Time (UTC), Thursday, 1 January 1970, not counting leap seconds.
The following DEFINE FUNCTION takes a number representing epoch time and converts it to a date-time value by using the HADD function to add the number of seconds represented by the input value in epoch time to the epoch base date:
DEFINE FUNCTION UNIX2GMT(INPUT/I9) UNIX2GMT/HYYMDS = HADD(DT(1970 JAN 1),'SECONDS',INPUT,8,'HYYMDS'); END
The following request uses this DEFINE FUNCTION to convert the epoch time 1449068652 to a date-time value:
DEFINE FILE GGSALES INPUT/I9=1449068652; OUTDATE/HMTDYYSb = UNIX2GMT(INPUT); END TABLE FILE GGSALES PRINT DATE NOPRINT INPUT OUTDATE WHERE RECORDLIMIT EQ 1 ON TABLE SET PAGE NOLEAD END
The output is shown in the following image:
WebFOCUS | |
Feedback |