Converting Date and Times from InterBase to C Format
From InterBase
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 TIME
and 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 thetime.h
header file. The following C code includes that header file, and declares a variable of typestruct tm
:#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_TIMESTAMP entry_date;
- The
ISC_TIMESTAMP
structure is declared inibase.h
, but the programmer must declare actual host-language variables of typeISC_TIMESTAMP
.
- The
- Retrieve a date from a table into the
ISC_TIMESTAMP
variable. - Convert the
ISC_TIMESTAMP
variable into a numeric C format with the InterBase function,isc_decode_timestamp()
. This function is also declared inibase.h
.isc_decode_timestamp()
requires two parameters, the address of theISC_TIMESTAMP
host-language variable, and the address of thestruct tm
host-language variable. For example, the following code fragment covertsentry_date
toentry_time
:isc_decode_timestamp(&entry_date, &entry_time);