3.4. Data Types for Dates and Times
The DATE
, TIME
and TIMESTAMP
data types are used to work with data containing dates and times. Dialect 3 supports all the three 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.
Dialect 1 |
Fractions of Seconds
If fractions of seconds are stored in date and time data types, Firebird stores them to ten-thousandths of a second. If a lower granularity is preferred, the fraction can be specified explicitly as thousandths, hundredths or tenths of a second in Dialect 3 databases of ODS 11 or higher.
Some useful knowledge about subseconds precision: The time-part of a
Deci-milliseconds precision is rare and is not currently stored in columns or variables. The best assumption to make from all this is that, although Firebird stores |
3.4.1. DATE
The DATE
data type in Dialect 3 stores only date without time. The available range for storing data is from January 01, 1 to December 31, 9999.
Dialect 1 has no “date-only” type.
In Dialect 1, date literals without a time part, as well as If, for some reason, it is important to you to store a Dialect 1 timestamp literal with an explicit zero time-part, the engine will accept a literal like |
3.4.2. TIME
The TIME
data type is available in Dialect 3 only. It stores the time of day within the range from 00:00:00.0000 to 23:59:59.9999.
If you need to get the time-part from DATE
in Dialect 1, you can use the EXTRACT
function.
Examples Using EXTRACT()
EXTRACT (HOUR FROM DATE_FIELD)
EXTRACT (MINUTE FROM DATE_FIELD)
EXTRACT (SECOND FROM DATE_FIELD)
See also the EXTRACT()
function in the chapter entitled Built-in Functions.
3.4.3. TIMESTAMP
The TIMESTAMP
data type is available in Dialect 3 and Dialect 1. It comprises two 32-bit words — a date-part and a time-part — to form a structure that stores both date and time-of-day. It is the same as the DATE
type in Dialect 1.
The EXTRACT
function works equally well with TIMESTAMP
as with the Dialect 1 DATE
type.
3.4.4. Operations Using Date and Time Values
The method of storing date and time values makes it possible to involve them as operands in some arithmetic operations. In storage, a date value or date-part of a timestamp is represented as the number of days elapsed since “date zero” — November 17, 1898 — whilst a time value or the time-part of a timestamp is represented as the number of seconds (with fractions of seconds taken into account) since midnight.
An example is to subtract an earlier date, time or timestamp from a later one, resulting in an interval of time, in days and fractions of days.
Operand 1 | Operation | Operand 2 | Result |
---|---|---|---|
|
|
|
|
|
| Numeric value |
|
|
|
|
|
|
| Numeric value |
|
|
| Numeric value |
|
|
|
| Number of days elapsed, within the range |
|
| Numeric value |
|
|
|
| Number of seconds elapsed, within the range |
|
| Numeric value |
|
|
|
| Number of days and part-day, within the range |
|
| Numeric value |
|
Notes The |
See also