SQL/MX Programming Manual for C and COBOL (G06.24+, H06.03+)

Host Variables in C/C++ Programs
HP NonStop SQL/MX Programming Manual for C and COBOL523627-004
3-24
Date-Time and Interval Data
Selecting Standard Date-Time Values
To retrieve standard date-time values (DATE, TIME, or TIMESTAMP, or the SQL/MP
DATETIME equivalents) from the database, declare a date-time (DATE, TIME, or
TIMESTAMP) host variable. For the required number of digits for DATE, TIME, or
TIMESTAMP values, see Table 3-3 on page 3-9.
If your C program performs string operations on the date-time host variable, you must
append a null terminator to the output string before processing it because the date-time
data types are internally processed as C character strings.
Table 3-7 lists the lengths of the target arrays for TIME and TIMESTAMP values, which
depend on the precision (the number of digits in the fractional seconds).
The TIME default precision is 0 (zero), and the TIMESTAMP default precision is 6.
Example
If a database has a BILLINGS table that consists of the CUSTNUM and
BILLING_DATE columns, this example selects the date-time value:
EXEC SQL BEGIN DECLARE SECTION;
struct billing_rec {
unsigned short hv_custnum;
DATE hv_billing_date;
...
} bill;
...
EXEC SQL END DECLARE SECTION;
...
EXEC SQL SELECT custnum, billing_date
INTO :bill.hv_custnum, :bill.hv_billing_date
FROM billings
WHERE custnum = :hv_this_customer;
... bill.hv_billing_date[10]='\0';
Table 3-7. Lengths of C Target Arrays for TIME and TIMESTAMP
TIME Precision Length TIMESTAMP Precision Length
TIME 9 TIMESTAMP 27
TIME(0) 9 TIMESTAMP(0) 20
TIME(1) 11 TIMESTAMP(1) 22
TIME(2) 12 TIMESTAMP(2) 23
TIME(3) 13 TIMESTAMP(3) 24
TIME(4) 14 TIMESTAMP(4) 25
TIME(5) 15 TIMESTAMP(5) 26
TIME(6) 16 TIMESTAMP(6) 27
C