Mapping Date or Time Data

Because C does not have a date or time datatype, SQL Server date or time columns are converted to characters by using the SQL Server default date format. For example:

mm dd yyyy hh:mm:ss[am | pm]

You can send dates to SQL Server from C character fields by using any of the character date formats that are acceptable to SQL Server. For a date without a time, use an 11-byte receiving field. If the data is truncated, note that the SQLWARN3 field of the SQLCA data structure is set. For other formats, use the Transact-SQL CONVERT statement. For example, to convert a time without a date, use a statement similar to this:


SELECT CONVERT(char, date, 8) FROM sales

When you attempt to put a fixed-length datatype into a buffer that is too small for it, an error occurs and no data is copied.