AMT Help Files

Database DateTime types

In AMT-COBOL there are 3 Date/Time database types, they are:

 

Type: Default Format:  Example string: Initial Value: 
DbsDate CCYY-MM-DD 1900-01-01  DATE'<Date format>' 
'<Date format>'
CURRENT_DATE 
DbsDateTime CCYY-MM-DD HH:MM:SS[.NNNNNNN] 2020-12-26 13:37:22.2565128 TIMESTAMP'<DateTime format>'
'<DateTime format>'
CURRENT_TIMESTAMP
DbsTime  HH:MM:SS[.NNNNNNN] 12:34:56.78901234  TIME'<Time format>'
'<Time format>
CURRENT_TIME

For the types with time, the number of fractional seconds can be set with the length property in the Object Inspector, with seven being the maximum number of fractional seconds that can be set.

When inserting or updating data in a Database Date Time type field, the data must be formatted according to the correct format for the type used.
See the table above for the default formats, the formats can be changed in the Dates node of the Application Options.

The Initial value format is also dependent on the format set in the Application Options and in the case of DbsDateTime and DbsTime also on the length property value.

For static initial value dates and times, an optional type keyword is allowed, e.g. DATE'2021-07-23'.

 

For dynamic initial value dates and times, the following functions can be used for their corresponding types: CURRENT_DATE, CURRENT_TIMESTAMP and CURRENT_TIME.
These will insert the current Date/Time at the moment of the record creation. 
See the 'Initial Value' column in the table above for an overview.

Changing date types or date formats to an other date type, date format, or to any other type, while having data in them will cause the data to become invalid.

 

Code example DbsDateTime length 2:

identification division.
 program-id. CURRENT-DATE-EXAMPLE.

 environment division.

 configuration section.

 input-output section.

 file-control.

 i-o-control.

 data division.

 file section.

 working-storage section.

 01  DATABASE-DATE-TIME // CCYY-MM-DD HH:MM:SS[.NN]

     05  DB-YEAR              PIC 9(4).
     05  FILLER               PIC X(1) VALUE '-'.
     05  DB-MONTH             PIC 9(2).
     05  FILLER               PIC X(1) VALUE '-'.
     05  DB-DAY               PIC 9(2).
     05  FILLER               PIC X(1) VALUE SPACE.
     05  DB-HOURS             PIC 9(2).
     05  FILLER               PIC X(1) VALUE ':'.
     05  DB-MINUTES           PIC 9(2).
     05  FILLER               PIC X(1) VALUE ':'.
     05  DB-SECONDS           PIC 9(2).
     05  FILLER               PIC X(1) VALUE '.'.
     05  DB-FRACTIONALSECONDS PIC 9(2).

 procedure division.

 main-entry section.

    MOVE 1948  TO DB-YEAR.
    MOVE    4  TO DB-MONTH.
    MOVE   28  TO DB-DAY.
    MOVE   12  TO DB-HOURS.
    MOVE   34  TO DB-MINUTES.
    MOVE   56  TO DB-SECONDS.
    MOVE   78  TO DB-FRACTIONALSECONDS.

    EXEC RDMS
         INSERT INTO T_DBTEST(TESTDATETIME)
         VALUES (:DATABASE-DATE-TIME)
    END-EXEC.
    
    STOPRUN.