HP 3000 Manuals

Using the System Date and Time [ HP RPG/XL Programmer's Guide ] MPE/iX 5.0 Documentation


HP RPG/XL Programmer's Guide

Using the System Date and Time 

There are two ways to retrieve the current date in an RPG program.

You can use the UDATE special field in Calculation and Output
Specifications.  UDATE is automatically initialized to the current date
when a program begins execution (the date is not reinitialized when
programs continue execution past midnight).

If you want to retrieve the date as well as the current time, use the
TIME (or TIME2) Calculation Specification operation.  Since TIME is
executed dynamically, the date and time are always current.  You may want
to use TIME, for example, to stamp transaction records before they are
written to tape.  TIME gets the time and, optionally, the date and stores
them in the Result Field in the format:  hhmmssmmddyy (or hhmmssddmmyy in
Foreign format).  For example, the date 10/29/86 and time 3:13:25 is
returned as 031325102986.  TIME2 returns the date and time in a
40-character formatted string.  The format for this string is shown below
along with an example of a date and time that might be returned:

day, mon dd, year, hh:mm xM   JULIAN:nnn

WED, OCT 29, 1986,  3:13 AM   JULIAN:304

You can specify which parts of the date and time to retrieve, if you
wish, by entering their positions in the Factor2 and Result Fields.

Figure 8-1 shows how to use the TIME2 operation to stamp output records
with the most current date and time.  Only the current time and the day
of the month are used in this example.

	       Click here to view figure.
          Figure 8-1.  Getting the System Date and Time 

            Comments 

 1       This line begins the data structure that holds the system date
         and time.

 2       This line specifies that the first field in the data structure
         contains the time.  The time is located in positions 20-27 of
         the date and time string returned by TIME2 (see line 5).

 3       This line specifies that the second field in data structure
         contains the day of the week.  The day of the week is located in
         positions 1-3 of the date and time string returned by TIME2 (see
         line 5).

 4       The line defines the third field in the data structure.  STAMP
         includes all 27 positions of the data structure.

 5       This line returns a string containing the system date and time.

         Columns 28-32 contain TIME2 to return a formatted date and time
         string.

         Columns 33-42 contain 1 to specify the starting location in the
         system date and time string where extraction is to begin.

         Columns 43-48 name the field, STAMP, where the system date and
         time string is stored.



MPE/iX 5.0 Documentation