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.

*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 /        
*                                                
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   11.01.2005                        
DATE IN FORMAT DD/MM/YYYY   11/01/2005                        
DATE IN FORMAT DD-MON-YYYY  11-Jan-2005                       
DATE IN FORMAT DDMONYYYY    11Jan2005                         
DATE IN GREGORIAN FORM      11January  2005                   
DATE IN FORMAT YYYY-MM-DD   2005-01-11                        
DATE IN FORMAT YYYYDDD      2005011                           
DATE IN FORMAT YYYYMMDD     20050111                          
DATE IN FORMAT MM/DD/YYYY   01/11/2005                        
DATE IN INTERNAL FORMAT     2005-01-11                        
                                                              
                                                              
TIME IN FORMAT HH:II:SS.T   14:42:05.4                        
TIME IN FORMAT HHIISST      1442054                           
TIME IN INTERNAL FORMAT     14:42:05                          
                                                              
CURRENT DATE 2005-01-11   CURRENT DATE + 14 DAYS    2005-01-25
CURRENT TIME 14:42:05     CURRENT TIME + 10 SECONDS 14:42:15