HGETZ: Storing the Current Coordinated Universal Time in a Date-Time Field

How to:

Available Languages: reporting, Maintain

HGETZ provides the current Coordinated Universal Time (UTC/GMT time, often called Zulu time). UTC is the primary civil time standard by which the world regulates clocks and time.

The value is returned in the desired date-time format. If millisecond or microsecond values are not available in your operating environment, the function retrieves the value zero for these components.


Top of page

x
Syntax: How to Store the Current Universal Date and Time in a Date-Time Field
HGETZ(length, output)

where:

length

Integer

Is the length of the returned date-time value. Valid values are:

  • 8 indicates a time value that includes milliseconds.
  • 10 indicates a time value that includes microseconds.
  • 12 indicates a time value that includes nanoseconds.
output

Date-time

Is the returned date-time value. It can be a field that contains the result or can be the format of the output value enclosed in single quotation marks. The format must be in date-time format (data type H).



Example: Storing the Current Universal Date and Time in a Date-Time Field (Reporting)

HGETZ stores the current universal date and time in DT2:

TABLE FILE VIDEOTRK
PRINT CUSTID AND COMPUTE
DT2/HYYMDm = HGETZ(10, 'HYYMDm');
WHERE CUSTID GE '2000' AND CUSTID LE '3000';
END

The output is:

  CUSTID  DT2                  
  ------  ---                        
  2165    2015/05/08 14:43:08.740000
  2187    2015/05/08 14:43:08.740000
  2280    2015/05/08 14:43:08.740000
  2282    2015/05/08 14:43:08.740000
  2884    2015/05/08 14:43:08.740000


Example: Calculating the Time Zone

The time zone can be calculated as a positive or negative hourly offset from GMT. Locations to the west of the prime meridian have a negative offset. The following request uses the HGETC function to retrieve the local time and the HGETZ function to retrieve the GMT time. The HDIFF function calculates the number of boundaries between them in minutes. The zone is found by dividing the minutes by 60:

DEFINE FILE EMPLOYEE
LOCALTIME/HYYMDS = HGETC(8, LOCALTIME);
UTCTIME/HYYMDS = HGETZ(8, UTCTIME);
MINUTES/D4= HDIFF(LOCALTIME, UTCTIME, 'MINUTES', 'D4');
ZONE/P3 = MINUTES/60;
END
TABLE FILE EMPLOYEE
PRINT EMP_ID NOPRINT OVER
LOCALTIME  OVER
UTCTIME OVER
MINUTES OVER
ZONE
IF RECORDLIMIT IS 1
END

The output is:

  LOCALTIME  2015/05/12 12:47:04
  UTCTIME    2015/05/12 16:47:04
  MINUTES                   -240
  ZONE                        -4

WebFOCUS