SQL to C: Timestamp
The identifier for the timestamp ODBC SQL data type is the following:
- SQL_TYPE_TIMESTAMP
The following table shows the ODBC C data types to which timestamp SQL data can be converted. For an explanation of the columns and terms in the table, see Converting Data from SQL to C Data Types.
C type identifier | Test | *TargetValuePtr | *StrLen_or_IndPtr | SQLSTATE |
---|---|---|---|---|
SQL_C_CHAR | BufferLength > Character byte length 20 <= BufferLength <= Character byte length BufferLength < 20 |
Data Truncated data[b] Undefined |
Length of data in bytes Length of data in bytes Undefined |
n/a 01004 22003 |
SQL_C_WCHAR | BufferLength > Character length 20 <= BufferLength <= Character length BufferLength < 20 |
Data Truncated data[b] Undefined |
Length of data in characters Length of data in characters Undefined |
n/a 01004 22003 |
SQL_C_BINARY | Byte length of data <= BufferLength Byte length of data > BufferLength |
Data Undefined |
Length of data in bytes Undefined |
n/a 22003 |
SQL_C_TYPE_DATE | Time portion of timestamp is zero[a] Time portion of timestamp is nonzero[a] |
Data Truncated data[c] |
6[f] 6[f] |
n/a 01S07 |
SQL_C_TYPE_TIME | Fractional seconds portion of timestamp is zero[a] Fractional seconds portion of timestamp is nonzero[a] |
Data[d] Truncated data[d], [e] |
6[f] 6[f] |
n/a 01S07 |
SQL_C_TYPE_TIMESTAMP | Fractional seconds portion of timestamp is not truncated[a] Fractional seconds portion of timestamp is truncated[a] |
Data[e] Truncated data[e] |
16[f] 16[f] |
n/a 01S07 |
[a] The value of BufferLength is ignored for this conversion. The driver assumes that the size of *TargetValuePtr is the size of the C data type.
[b] The fractional seconds of the timestamp are truncated.
[c] The time portion of the timestamp is truncated.
[d] The date portion of the timestamp is ignored.
[e] The fractional seconds portion of the timestamp is truncated.
[f] This is the size of the corresponding C data type.
When timestamp SQL data is converted to character C data, the resulting string is in the "yyyy-mm-dd hh:mm:ss[.f...]" format, where up to nine digits can be used for fractional seconds. This format is not affected by the Windows country/region setting. (Except for the decimal point and fractional seconds, the entire format must be used, regardless of the precision of the timestamp SQL data type.)