Converting Date and Times from InterBase to C Format
Go Up to Working with Conversions
The following steps show how to convert the
TIMESTAMP data type from InterBase to C format; the same steps could be used to convert the
DATE data types by substituting the appropriate API call above. Starting with InterBase 6, the
TIMESTAMP data type replaces the older
DATE data type used in earlier versions.
To select a timestamp from a table, and convert it to a form usable in a C language program, follow these steps:
- 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> #include <ibase.h> . . . struct tm entry_time; . . .
- Note: To create host-language time structures in languages other than C and C++, see the host-language reference manual.
- Create a host variable of type
ISC_TIMESTAMP. 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
- Retrieve a date from a table into the
- Convert the
ISC_TIMESTAMPvariable into a numeric C format with the InterBase function,
isc_decode_timestamp(). This function is also declared in
isc_decode_timestamp()requires two parameters, the address of the
ISC_TIMESTAMPhost-language variable, and the address of the
struct tmhost-language variable. For example, the following code fragment coverts