Date and Time System Variables

This document covers the following topics:


Usage

The date and time system variables listed below may be specified in the following places:

The contents of date and time system variables as generated by Natural are non-modifiable, which means that in a Natural program you cannot assign another value to any of them.

*DAT* - Date System Variables

All date system variables contain the current date. The format of the date is different for each date variable, as indicated below.

Date Variable Format/Length Date Format*
*DATD A8 DD.MM.YY
*DAT4D A10 DD.MM.YYYY
*DATE A8 DD/MM/YY
*DAT4E A10 DD/MM/YYYY
*DATG A15 DDmonthnameYYYY (Gregorian date)
*DATI A8 YY-MM-DD
*DAT4I A10 YYYY-MM-DD
*DATJ A5 YYJJJ (Julian date)
*DAT4J A7 YYYYJJJ (Julian date)
*DATN N8 YYYYMMDD
*DATU A8 MM/DD/YY
*DAT4U A10 MM/DD/YYYY
*DATV A11 DD-MON-YYYY
*DATVS A9 DDMONYYYY
*DATX D internal date format

* D = day, J = Julian day, M = month, Y = year, MON = leading three bytes of the month's name as in *DATG

*TIM* - Time System Variables

At runtime, the content of a time system variable is evaluated anew each time the variable is referenced in a Natural program. The format of the time is different for each time variable, as indicated below.

Time Variable Format/Length Explanation
*TIMD (r) N7 Can only be used in conjunction with a previous SETTIME statement.

Contains the time that has elapsed after the SETTIME statement was executed (in the format HHIISST (*)).

(r) represents the statement label or source-code line number of the SETTIME statement used as the basis for *TIMD.

*TIME A10 Contains the time of day in the format HH:II:SS.T (*).
*TIME-OUT N5 Contains the number of seconds remaining before the current transaction will be timed out (only available with Natural Security).

*TIME-OUT is 0 if transaction mode has not been entered. Transaction mode is entered with the execution of a FIND, READ or GET statement that reads a database record for the purpose of updating or deleting the record.

*TIME-OUT is reset to 0 when an END TRANSACTION or BACKOUT TRANSACTION statement is executed.

*TIMESTMP B8

Machine-internal store clock value as provided by the mainframe machine instruction STCK (Store Clock format).

For more information about the meaning of this value, please refer to the IBM documentation.

The processing of store clock values is described in Programming Guide > Further Programming Aspects > Processing of Store Clock Values.

*TIMESTMPX B16

Machine-internal store clock value as provided by the mainframe machine instruction STCKE (Store Clock Extended format).

For more information about the meaning of this value, please refer to the IBM documentation.

The processing of extended store clock values is described in Programming Guide > Further Programming Aspects > Processing of Store Clock Values.

*TIMN N7 Contains the time of day in format HHIISST (*).
*TIMX T Contains the time of day in internal time format.

* H = hour, I = minute, S = second, T = tenth of a second.

Example of Date and Time System Variables

** Example 'DATIVAR': Date and time system variables                    
************************************************************************
DEFINE DATA LOCAL                                                       
1 #DATE (D)                                                             
1 #TIME (T)                                                             
END-DEFINE                                                              
*                                                                       
WRITE NOTITLE                                                           
  'DATE IN FORMAT DD.MM.YYYY  '   *DAT4D /                              
  'DATE IN FORMAT DD/MM/YYYY  '   *DAT4E /                              
  'DATE IN FORMAT DD-MON-YYYY '   *DATV  /                              
  'DATE IN FORMAT DDMONYYYY   '   *DATVS /                              
  'DATE IN GREGORIAN FORM     '   *DATG  /                              
  'DATE IN FORMAT YYYY-MM-DD  '   *DAT4I /                              
  'DATE IN FORMAT YYYYDDD     '   *DAT4J /                              
  'DATE IN FORMAT YYYYMMDD    '   *DATN (AD=L) /                        
  'DATE IN FORMAT MM/DD/YYYY  '   *DAT4U /                              
  'DATE IN INTERNAL FORMAT    '   *DATX (DF=L) ///                      
  'TIME IN FORMAT HH:II:SS.T  '   *TIME /
  'TIME IN FORMAT HHIISST     '   *TIMN (AD=L) / 
  'TIME IN INTERNAL FORMAT    '   *TIMX /
  'TIME IN STORE CLOCK FORMAT '   *TIMESTMP /
  'TIME IN EXT. STCK FORMAT   '   *TIMESTMPX /       
*                                                
MOVE *DATX TO #DATE                              
ADD 14 TO #DATE                                  
WRITE 'CURRENT DATE'              *DATX (DF=L) 3X
      'CURRENT DATE + 14 DAYS   ' #DATE (DF=L)   
*                                                
MOVE *TIMX TO #TIME                              
ADD 100 TO #TIME                                 
WRITE 'CURRENT TIME'              *TIMX 5X       
      'CURRENT TIME + 10 SECONDS' #TIME          
*                                                
END                                             

Output of program DATIVAR:

DATE IN FORMAT DD.MM.YYYY   05.05.2023
DATE IN FORMAT DD/MM/YYYY   05/05/2023
DATE IN FORMAT DD-MON-YYYY  05-May-2023
DATE IN FORMAT DDMONYYYY    05May2023
DATE IN GREGORIAN FORM      05May      2023
DATE IN FORMAT YYYY-MM-DD   2023-05-05
DATE IN FORMAT YYYYDDD      2023125
DATE IN FORMAT YYYYMMDD     20230505
DATE IN FORMAT MM/DD/YYYY   05/05/2023
DATE IN INTERNAL FORMAT     2023-05-05


TIME IN FORMAT HH:II:SS.T   13:26:06.4
TIME IN FORMAT HHIISST      1326064
TIME IN INTERNAL FORMAT     13:26:06
TIME IN STORE CLOCK FORMAT  DD400D6D2A5C700E
TIME IN EXT. STCK FORMAT    00DD400D6D2A5C800E00000000000000

CURRENT DATE 2023-05-05   CURRENT DATE + 14 DAYS    2023-05-19
CURRENT TIME 13:26:06     CURRENT TIME + 10 SECONDS 13:26:16