Open Client supports six datetime types: CS_DATE, CS_TIME, CS_DATETIME, CS_DATETIME4, CS_BIGDATETIME, and CS_BIGTIME. These datatypes are intended to hold 8-byte and 4-byte datetime values.
The CS_BIGDATETIME and CS_BIGTIME datatypes provide microsecond-level precision for time data. These datatypes are intended to hold 8-byte binary values.These datatypes function similarly to the respective CS_DATETIME and CS_TIME datatypes: The CS_BIGDATETIME datatype can be used anywhere that the CS_DATETIME datatype can be used, and the CS_BIGTIME datatype can be used anywhere that the CS_TIME datatype can be used. All Open Client and Open Server routines that can be applied to the CS_DATETIME and CS_TIME datatypes can also be applied to the CS_BIGDATETIME and CS_BIGTIME datatypes.
CS_DATE corresponds to the Adaptive Server Enterprise date datatype with a range of legal values from January 1, 0001 to December 31, 9999.
CS_TIME corresponds to the Adaptive Server Enterprise time datatype, with a range of legal values from 12:00:00.000 to 11:59:59:999 with a precision of 1/300th of a second (3.33 ms).
CS_DATETIME corresponds to the Adaptive Server Enterprise datetime datatype, with a range of legal values from January 1, 1753 to December 31, 9999, with a precision of 1/300th of a second (3.33 ms).
CS_DATETIME4 corresponds to the Adaptive Server Enterprise smalldatetime datatype, with a range of legal values from January 1, 1900 to June 6, 2079, with a precision of 1 minute.
CS_BIGDATETIME corresponds to the Adaptive Server Enterprise bigdatetime datatype and contains the number of microseconds that have passed since January 1, 0000 00:00:00.000000. The range of legal CS_BIGDATETIME values is from January 1, 0001 00:00:00.000000 to December 31, 9999 23:59:59.999999.
January 1, 0000 00:00:00.000000 is the base starting value from which microseconds are counted. Any value earlier than January 1, 0001 00:00:00.000000 is invalid.
CS_BIGTIME corresponds to the Adaptive Server Enterprise bigtime datatype and indicates the number of microseconds that have passed since the beginning of the day. The range of legal CS_BIGTIME values is from 00:00:00.000000 to 23:59:59.999999.
CS_BIGDATETIME and CS_BIGTIME data is presented to the client in the native-byte order (endianness) of the underlying client platform. Any necessary byte-swapping is performed at the server before the data is sent to the client, or after the data is received from the client.
An application can call the CS-Library routine cs_convert to initialize a datetime type from a character string. cs_convert recognizes all of the date and time formats valid for Transact-SQL datetime character strings. See the “Datatypes” topic in the Adaptive Server Enterprise Reference Manual.
cs_convert can also convert a CS_DATETIME or CS_DATETIME4 value into a character string.
Other routines that are useful when working with datetime values include:
cs_cmp, which compares two data values.
cs_dt_crack, which maps a datetime value to a CS_DATEREC structure. A CS_DATEREC contains distinct fields for the different parts of a datetime value.
cs_dt_info, which retrieves language-specific datetime information such as day names. This routine also configures the format for converting datetime data values to character strings.
cs_convert, cs_cmp, cs_dt_crack, and cs_dt_info use locale information that is specified indirectly, using the CS_CONTEXT, or directly, using a CS_LOCALE structure. (See “CS_LOCALE”.) An application can change the locale information for a CS_CONTEXT by calling cs_config to set the CS_LOC_PROP property for the context.