C to SQL: Timestamp

The identifier for the timestamp ODBC C data type is:

SQL_C_TYPE_TIMESTAMP

The following table shows the ODBC SQL data types to which timestamp C data may be converted. For an explanation of the columns and terms in the table, see “Converting Data from C to SQL Data Types.”


SQL type identifier

Test
SQL-
STATE
SQL_CHAR
SQL_VARCHAR
SQL_LONGVARCHAR
Column byte length >= Character byte length.

19 <= Column byte length < Character byte length.

Column byte length < 19.

Data value is not a valid timestamp.

n/a

22001

22001

22008

SQL_WCHAR
SQL_WVARCHAR
SQL_WLONGVARCHAR
Column character length >= Character length of data.

19 <= Column character length < Character length of data.

Column character length < 19.

Data value is not a valid timestamp.

n/a

22001

22001

22008

SQL_TYPE_DATE Time fields are zero.

Time fields are non-zero.

Data value does not contain a valid date.

n/a

22008

22007

SQL_TYPE_TIME Fractional seconds fields are zero. [a]

Fractional seconds fields are non-zero. [a]

Data value does not contain a valid time.

n/a

22008

22007

SQL_TYPE_
TIMESTAMP
Fractional seconds fields are not truncated.

Fractional seconds fields are truncated.

Data value is not a valid timestamp.

n/a

22008

22007


[a]The date fields of the timestamp structure are ignored.

For information about what values are valid in a SQL_C_TIMESTAMP structure, see “C Data Types.”

When timestamp C data is converted to character SQL data, the resulting character data is in the “yyyy-mm-dd hh:mm:ss[.f...]” format.

The driver ignores the length/indicator value when converting data from the timestamp C data type and assumes that the size of the data buffer is the size of the timestamp C data type. The length/indicator value is passed in the StrLen_or_Ind argument in SQLPutData and in the buffer specified with the StrLen_or_IndPtr argument in SQLBindParameter. The data buffer is specified with the DataPtr argument in SQLPutData and the ParameterValuePtr argument in SQLBindParameter.