DATE and DATETIME data types
Informix®
Informix provides two data types to store date and time information:
DATE= for year, month and day storage.DATETIME= for year to fraction (1-5) storage.
The DATE type is stored as an INTEGER with the number of days
since 1899/12/31.
The DATETIME type can be defined with various time units, by specifying a start
and end qualifier. For example, you can define a datetime to store an hour-to-second time value with
DATETIME HOUR TO SECOND.
DATETIME can be represented with a character string literal, or as
DATETIME()
literals:'2017-12-24 15:45:12.345' -- a DATETIME YEAR TO FRACTION(3)
'15:45' -- a DATETIME HOUR TO MINUTE
DATETIME(2017-12-24 12:45) YEAR TO MINUTE
DATETIME(12:45:56.333) HOUR TO FRACTION(3)DATE / DATETIME data, if the string contains matching environment
parameters. The string to date conversion rules for DATE is defined by the DBDATE
environment variable. The string to datetime format for DATETIME is defined by the
GL_DATETIME environment variable.DATETIME values is always ISO (YYYY-MM-DD hh:mm:ss.fffff)
Informix supports date arithmetic on
DATE and DATETIME values. The result of an arithmetic expression
involving dates/times is an INTEGER number of days when only DATE values are used,
and an INTERVAL value if a DATETIME is used in the expression.
Informix automatically converts an
INTEGER to a DATE when the integer is used to set a value of a
date column.
Oracle® MySQL and MariaDB
MySQL and MariaDB provide the following data type to store date and time data:
| MySQL data type | Description |
|---|---|
DATE |
for year, month, day storage |
TIME[(n)] |
for hour, minute, second and fraction of second storage |
DATETIME[(n)] |
for year, month, day, hour, minute, second and fraction of second storage |
TIMESTAMP |
Like DATETIME, but is automatically updated when row is touched |
Like Informix, MySQL can convert quoted strings to
datetime data based on the ISO datetime format (YYYY-MM-DD hh:mm:ss).
In MySQL, the result of an arithmetic expression involving DATE values is an
INTEGER representing a number of days.
Solution
Use the following conversion rules to map Informix date/time types to MySQL date/time types:
| Informix data type | MySQL data type |
|---|---|
DATE |
DATE |
DATETIME HOUR TO MINUTE |
TIME |
DATETIME HOUR TO SECOND |
TIME |
DATETIME HOUR TO FRACTION(p) |
TIME(p) |
DATETIME YEAR TO MINUTE |
DATETIME |
DATETIME YEAR TO SECOND |
DATETIME |
DATETIME YEAR TO FRACTION(p) |
DATETIME(p) |
DATETIME q1 TO q2 (others than above) |
DATETIME(p) |
DATE and
DATETIME types translation can be controlled with the following FGLPROFILE
entries:dbi.database.dsname.ifxemul.datatype.date = { true | false }
dbi.database.dsname.ifxemul.datatype.datetime = { true | false }
For more details see IBM Informix emulation parameters in FGLPROFILE.MySQL and Informix DATE data types
both store year, month, day values.
DATETIME types: DATETIME HOUR TO MINUTEis converted to MySQLTIME(seconds set to 00).DATETIME HOUR TO SECONDis converted to MySQLTIME.DATETIME HOUR TO FRACTION(n)is converted to MySQLTIME(n).DATETIME YEAR TO MINUTEis converted to MySQLDATETIME(seconds set to 00).DATETIME YEAR TO SECONDis converted to MySQLDATETIME.DATETIME YEAR TO FRACTION(n)is converted to MySQLDATETIME(n).
Other DATETIME types will be mapped to MySQL DATETIME(N)
columns. Missing date or time parts default to 1900-01-01 00:00:00.
DATETIME. If you try to store a DATETIME
q1 TO FRACTION(p) with such an old server version,
the fractional part is lost.