There are two ways in which 4GL can assign value to a DATETIME variable:
As a DATETIME literal
As a character string
In DATETIME literal, DATETIME keyword is followed by whole numbers enclosed in parentheses that represent date and time values:
Numeric Date and Time |
A numeric DATETIME value entered in compliance with the format described below |
Day Time Qualifier |
The scale (precision) specification that matches the assigned value |
YYYY |
A numeric indication of a year represented by integers from 0001 to 9999 |
MM |
A numeric indication of a month represented by an integer from 1 to 12 |
DD |
A numeric indication of a day represented by an integer from 01 to 31 |
(Hyphen) |
A delimiter used between year and month and between month and day |
Space |
A space is required between year-month-day sequence and time sequence |
hh |
A numeric indication of hours represented by an integer from 0 to 23 |
mm |
A numeric indication of minutes represented by an integer from 0 to 59 |
ss |
A numeric indication of seconds represented by an integer from 0 to 59 |
: (Colon) |
A delimiter used between hours and minutes and between minutes and seconds |
fff |
A numeric indication of the fractions of a second: up to five digits |
. (Dot) |
A delimiter which separates fractions from seconds |
The default precision for the year is 4, month, hours, minutes and seconds have the default precision of 2 and this cannot be changed. In the source code, this diagram may be represented as follows:
LET my_dt = DATETIME (10-03-15 21:05:49.032) YEAR TO FRACTION (3)
The value "2010-03-15 21:05:49.032" will be assigned to the variable my_datetime, though only 2 digits have been entered for YEAR value, 4GL retrieves the first to digits from the system clock-calendar.
As well as in DATE data type you must include leading zeros to the year number, if you want to specify a year of the First Century (E.g. 0067 for 67 A.D.). If a user enters one or two symbols for a year value (1 or 01), they will not be regarded as a year of the First Century; 4GL uses the settings of the DBCENTURY environment variable to restore the first two or three digits of the year. To override the settings of this variable for the DATETIME data type, the individual field attribute CENTURY may be used for the form fields of DATETIME type.
It is not necessary to specify every time unit from the declared data type, you can specify only units you need. E.g. if you have declared a DATETIME variable with YEAR TO MINUTE precision, any values can be assigned to it provided that they do not exceed the declared precision. This means you can assign a MONTH TO HOUR, MONTH TO MINUTE, YEAR TO MINUTE, YEAR TO MONTH or YEAR TO HOUR values to it, but values that include SECOND and FRACTION will not be valid for a variable declared with YEAR TO MINUTE precision. You need to specify only those time units in the numeric value which correspond to the qualifier you use within the DATETIME literal. You cannot use them in random order or miss the successive time units between the largest and the smallest time unit you use.
If not all of the time units that have been declared for the variable are specified while assigning a value, 4GL expands the DATETIME value automatically to fill the time units to which no values were assigned. The missing values larger than the largest value assigned to a variable are retrieved from the system clock-calendar. If the omitted units are smaller than the smallest assigned value they are set to zero (MONTH and DAY are set to 1).