SQL/MX 3.2.1 Programming Manual for C and COBOL (H06.26+, J06.15+)

Host Variables in C/C++ Programs
HP NonStop SQL/MX Release 3.2.1 Programming Manual for C and COBOL663854-005
3-35
Date-Time and Interval Data
DATE Representation
You can insert or retrieve date-time values in any of three formats, independently of the
SQL column definition. For example, you can specify formats such as 09/15/1993,
1993-09-15, or 15.09.1993. You control the display format by inserting the value in the
format you want and retrieving the value by using the DATEFORMAT function. See the
DATEFORMAT function in the SQL/MX Reference Manual.
For example, if a table in the database has this column definition:
HIRE_DATE DATE
The host variable representation for December 22, 1988, in DEFAULT format is:
A DATE host variable in DEFAULT format is represented as an 11-character string,
including 10 characters—with hyphens (-) as field separators—plus a character (empty
space) for a null terminator.
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-11.
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).
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
1 9 8 8 1 2 2 2

Year Separator Month Separator Day
Null