The DATE
, TIME
and TIMESTAMP
data types are used to work with data containing dates and times.
Time zone support is available using the types TIME WITH TIME ZONE
and TIMESTAMP WITH TIME ZONE
.In this language reference, we’ll use TIME
and TIMESTAMP
to refer both to the specific types without time zone — TIME [WITHOUT TIME ZONE]
and TIMESTAMP [WITHOUT TIME ZONE]
— and aspects of both the without time zone and with time zone types, which one we mean is usually clear from the context.
Important
|
The data types TIME WITHOUT TIME ZONE , TIMESTAMP WITHOUT TIME ZONE and DATE are defined to use the session time zone when converting from or to a TIME WITH TIME ZONE or TIMESTAMP WITH TIME ZONE .TIME and TIMESTAMP are synonymous to their respective WITHOUT TIME ZONE data types.
|
Dialect 3 supports all the five types, while Dialect 1 has only DATE
.The DATE
type in Dialect 3 is “date-only”, whereas the Dialect 1 DATE
type stores both date and time-of-day, equivalent to TIMESTAMP
in Dialect 3.Dialect 1 has no “date-only” type.
Note
|
Dialect 1 DATE data can be defined alternatively as TIMESTAMP and this is recommended for new definitions in Dialect 1 databases.
|
Fractions of Seconds
If fractions of seconds are stored in date and time data types, Firebird stores them to ten-thousandths of a second (100 microseconds or deci-milliseconds).If a lower granularity is preferred, the fraction can be specified explicitly as thousandths, hundredths or tenths of a second, or second, in Dialect 3 databases of ODS 11 or higher.
Note
|
Some Useful Knowledge about Sub-second Precision
The time-part of a TIME or TIMESTAMP is a 32-bit integer, with room for deci-milliseconds (or 100 microseconds) precision and time values are stored as the number of deci-milliseconds elapsed since midnight.The actual precision of values stored in or read from time(stamp) functions and variables is:
-
CURRENT_TIME and LOCALTIME default to seconds precision and can be specified up to milliseconds precision with CURRENT_TIME({0|1|2|3}) or LOCALTIME({0|1|2|3})
-
CURRENT_TIMESTAMP and LOCALTIMESTAMP default to milliseconds precision.Precision from seconds to milliseconds can be specified with CURRENT_TIMESTAMP({0|1|2|3}) or LOCALTIMESTAMP({0|1|2|3})
-
Literal 'NOW' defaults to milliseconds precision
-
Functions DATEADD() and DATEDIFF() support up to deci-milliseconds precision with MILLISECOND
-
The EXTRACT() function returns up to deci-milliseconds precision with the SECOND and MILLISECOND arguments
-
the ‘+ ’ and ‘- ’ operators work with deci-milliseconds precision.
Deci-milliseconds precision is not supported by all drivers and access components.The best assumption to make from all this is that, although Firebird stores TIME and the TIMESTAMP time-part values as the number of deci-milliseconds (10-4 seconds) elapsed since midnight, the actual precision could vary from seconds to milliseconds.
|