Working with Dates and Times
Go Up to Embedded SQL Guide
Most host languages do not support the DATE
, TIME
, and TIMESTAMP
data types. Instead, they treat dates as strings or structures. InterBase supports DATE
and TIME
data types that are stored as single long integers, and a TIMESTAMP
data type that is stored in tables as two long integers. An InterBase DATE
data type includes information about year, month, and day of the month, the TIME
data type includes information about time, and the TIMESTAMP
data type is a combination of the two.
This chapter discusses how to SELECT
, INSERT
, and UPDATE
dates from tables in SQL applications using the following isc call interface routines:
isc_decode_sql_date()
converts the InterBase internal date format to the C time structure.isc_encode_sql_date()
converts the C time structure to the internal InterBase date format.isc_decode_sql_time()
converts the InterBase internal time format to the C time structure.isc_encode_sql_time()
converts the C time structure to the internal InterBase time format.isc_decode_timestamp()
converts the InterBase internal timestamp format to the C time structure; this was formerlyisc_decode_date()
.isc_encode_timestamp()
converts the C time structure to the InterBase internal timestamp format; this was formerlyisc_encode_date()
.
See the API Guide for a description of each of these functions.
This chapter also discusses how to use the CAST()
function to translate DATE
, TIME
, and TIMESTAMP
data types into each other or into CHAR
data types and back again, and how to use the DATE
literals (YESTERDAY
, TOMORROW
, NOW
, and TODAY
) when selecting and inserting dates.
Topics
- Querying the Database for Current Date and Time Information
- Selecting Dates and Times
- Formatting Dates for Input
- Inserting Dates and Times
- Updating Dates and Times
- Using CAST( ) to Convert Dates and Times
- Using Date Literals
- Adding and Subtracting Date and Time Data Types
- Comparing Dates and Times
- Using Date and Time Data Types with Aggregate Functions