To avoid problems in expanding abbreviated years, applications should require entry of 4-digit years, and should always display years as four digits. The DBCENTURY environment variable specifies how to expand literal DATE and DATETIME values that are entered with abbreviated year values.
.-R-----. >>-setenv--DBCENTURY--+-F-----+-------------------------------->< '-+-C-+-' '-P-'
When DBCENTURY is not set (or is set to R), the first two digits of the current year are used to expand 2-digit year values. For example, if today's date is 09/30/2003, then the abbreviated date 12/31/99 expands to 12/31/2099, and the abbreviated date 12/31/00 expands to 12/31/2000.
The R, P, F, and C settings choose algorithms for expanding two-digit years.
Setting | Algorithm |
---|---|
R = Current | Use the first two digits of the current year to expand the year value. |
P = Past | Expanded dates are created by prefixing the abbreviated year value with 19 and 20. Both dates are compared to the current date, and the most recent date that is earlier than the current date is used. |
F = Future | Expanded dates are created by prefixing the abbreviated year value with 20 and 21. Both dates are compared to the current date, and the earliest date that is later than the current date is used. |
C = Closest | Expanded dates are created by prefixing the abbreviated year value with 19, 20, and 21. These three dates are compared to the current date, and the date that is closest to the current date is used. |
Settings are case sensitive, and no error is issued for invalid settings. If you enter f (for example), then the default (R) setting takes effect. The P and F settings cannot return the current date, which is not in the past or future.
Years entered as a single digit are prefixed with 0 and then expanded. Three-digit years are not expanded. Pad years earlier than 100 with leading zeros.
The following examples illustrate how various settings of DBCENTURY cause abbreviated years to be expanded in DATE and DATETIME values.
Example data type: DATE Current date: 4/6/2003 User enters: 1/1/1 Prefix with "19" expansion : 1/1/1901 Prefix with "20" expansion: 1/1/2001 Analysis: Both are prior to current date, but 1/1/2001 is closer to current date.
Example data type: DATETIME year to month Current date: 5/7/2005 User enters: 1-1 Prefix with "20" expansion: 2001-1 Prefix with "21" expansion: 2101-1 Analysis: Only date 2101-1 is after the current date, so it is chosen.
Example data type: DATE Current date: 4/6/2000 User enters: 1/1/1 Prefix with "19" expansion : 1/1/1901 Prefix with "20" expansion: 1/1/2001 Prefix with "21" expansion: 1/1/2101 Analysis: Here 1/1/2001 is closest to the current date, so it is chosen.
Example data type: DATETIME year to month Current date: 4/6/2000 User enters: 1-1 Prefix with "20" expansion: 2001-1 Example data type: DATE Current date: 4/6/2003 User enters: 0/1/1 Prefix with "20" expansion: 2000/1 Analysis: In both examples, the Prefix with "20" algorithm is used.
Setting DBCENTURY does not affect IBM Informix products when the locale specifies a non-Gregorian calendar, such as Hebrew or Islamic calendars. The leading digits of the current year are used for alternate calendar systems when the year is abbreviated.
When an expression in a database object (including a check constraint, fragmentation expression, SPL routine, trigger, or UDR) contains a literal date or DATETIME value in which the year has one or two digits, the database server evaluates the expression using the setting that DBCENTURY (and other relevant environment variables) had when the database object was created (or was last modified). If DBCENTURY has been reset to a new value, the new value is ignored when the abbreviated year is expanded.
For example, suppose a user creates a table and defines the following check constraint on a column named birthdate:
birthdate < '09/25/50'
The expression is interpreted according to the value of DBCENTURY when the constraint was defined. If the table that contains the birthdate column is created on 09/23/2000 and DBCENTURY =C, the check constraint expression is consistently interpreted as birthdate < '09/25/1950' when inserts or updates are performed on the birthdate column. Even if different values of DBCENTURY are set when users perform inserts or updates on the birthdate column, the constraint expression is interpreted according to the setting at the time when the check constraint was defined (or was last modified).
Database objects created on some earlier versions of Dynamic Server do not support the priority of creation-time settings.
After the objects are redefined, date literals within expressions of the objects will be interpreted according to the environment at the time when the object was created or was last modified. Otherwise, their behavior will depend on the runtime environment and might become inconsistent if this changes.
Administration of a database that includes a mix of legacy objects and new objects might become difficult because of differences between the new and the old behavior for evaluating date expressions. To avoid this, it is recommended that you redefine any legacy objects.
The value of DBCENTURY and the current date are not the only factors that determine how the database server interprets date and DATETIME values. The DBDATE, DBTIME, GL_DATE, and GL_DATETIME environment variables can also influence how dates are interpreted. For information about GL_DATE and GL_DATETIME, see the IBM Informix: GLS User's Guide.