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.
SQLite
SQLite 3 does not have a native type for date/time storage, but you can use data/time type names
and functions based on the string representation of dates and times. The date/time values are stored
in the TEXT
native type.
The date/time functions of SQLite are based on standard DATE (YYYY-MM-DD)
,
TIME (hh:mm:ss)
and TIMESTAMP (YYYY-MM-DD hh:mm:ss)
concepts.
For maximum flexibility with other RDBMS SQL languages, SQLite allows you to define table columns
with your own type names. You can for example use the SMALLDATETIME
,
SMALLTIME
, TIME(N)
, DATETIME(N)
type names.
Solution
SMALLTIME
, TINYDATETIME
, to map original Informix date/time types. This allows the SQLite ODI driver
and the fgldbsch tool detect the exact date/time type of a column. When a
CREATE TABLE
statement in a BDL program uses DATETIME HOUR TO
MINUTE
, it is mapped to a SMALLTIME
by the ODI driver, and when extracting
the database schema, fgldbsch can recognized SMALLTIME
as a BDL
/ Informix
DATETIME HOUR TO MINUTE
column.Use the following conversion rules to map Informix date/time types to SQLite date/time (pseudo) types:
Informix data type | SQLite (pseudo data type |
---|---|
DATE |
DATE |
DATETIME HOUR TO MINUTE |
SMALLTIME |
DATETIME HOUR TO SECOND |
TIME |
DATETIME HOUR TO FRACTION(n) |
TIME(n) |
DATETIME YEAR TO DAY |
TINYDATETIME |
DATETIME YEAR TO MINUTE |
SMALLDATETIME |
DATETIME YEAR TO SECOND |
DATETIME |
DATETIME YEAR TO FRACTION(n) |
DATETIME(n) |
DATETIME q1 TO q2 (different from
above) |
TIMESTAMP |
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.In SQL statements, CURRENT expressions are converted to SQLite strftime('%Y-%m-%d
%H:%M:%S','now')
. The SQLite 'now'
option returns the current date/time in
UTC, while the FGL runtime system CURRENT instruction returns the current local time. Both values
can different. Always consider using SQL parameters with program variables assigned by the CURRENT
instruction of Genero BDL, instead of using CURRENT instructions in SQL statements.