As explained in the Datetime FIelds page, a field of
datetime
type is a 64 bit integer value used to store the date and time in databases and the precision of datetime
values is determined by the runtime parameterDATETIME_PRECISION
which represents the number of ticks per second. The default value forDATETIME_PRECISION
is 1000, which means that the database stores adatetime
value as the number of milliseconds since the EPOCH (i.e. 00:00:00 UTC 1 January 1970).For example , the following code snippet defines a
Datetime
fieldd
and a sequence ofdatetime
valuessd
:class T { datetime d; sequence<datetime> sd; }The resolution of
Date
fields can be changed by an application via the runtime option. The
RT_OPTION_DATETIME_PRECISION
DATETIME_PRECISION
can be set to 1 to store the number of seconds, or 1000000 (1,000,000) to store the number of microseconds. For example:exdb.runtime_setoption(exdb.RuntimeOption.MCO_RT_OPTION_DATETIME_PRECISION, 1000000)The following code snippet demonstrates how to store and load
Date
values using SQL:import datetime ... d = datetime.datetime(2011, 9, 10, 9, 30) sd = [datetime.datetime(2011, 9, 10, 9, i) for i in range(1,30) ] cursor = con.cursor() cursor.execute("INSERT INTO T VALUES(?,?)", (d, sd)) ... cursor = con.cursor() cursor.execute("SELECT d, sd FROM T") for row in cursor: d,sd = row sds = [item for item in sd] print "d: %s. sd : %s" % (d, sds) cursor.close()