Converting Dates from C to InterBase Format
Go Up to Working with Conversions
The following steps show how to convert the
TIMESTAMP data type from C to InterBase format; the same steps could be used to convert the
DATE data types by substituting the appropriate API call listed on the parent page. To insert a timestamp in a table, it must be converted from the host-language format into InterBase format, and then stored. To perform the conversion and insertion in a C program, follow these steps:
- 1. Create a host variable for a C time structure. Most C and C++ development systems provide a type,
struct tm, for the C time structure in the
time.hheader file. The following C code includes that header file, and declares a variable of type
#include <time.h>; . . . struct tm entry_time; . . .
- To create host-language time structures in languages other than C and C++, see the host-language reference manual.
- 2. Create a host variable of type
ISC_TIMESTAMP, for use by InterBase. For example, the host-variable declaration might look like this:
ISC_TIMESTAMPstructure is declared in
ibase.h, but the programmer must declare actual host-language variables of type
- 3. Put date information into
- 4. Use the InterBase
isc_encode_sql_date()function to convert the information in
entry_timeinto InterBase internal format and store that formatted information in the
ISC_TIMESTAMPhost variable (
entry_datein the example). This function is also declared in
isc_encode_timestamp()requires two parameters, the address of the C time structure, and the address of the
ISC_TIMESTAMPhost-language variable. For example, the following code converts
- 5. Insert the date into a table.