This example shows how to cast a number to a CHAR data type. Table 5-shows which built-in datatypes can be cast into which other built-in datatypes. If a DATE is converted to a TIMESTAMP, the TIME component of the resulting TIMESTAMP is always 00:00:00.
If a TIME data value is converted to a TIMESTAMP, the DATE component is set to the value of CURRENT_ DATE at the time the CAST is executed. In SQL Server, you can use CONVERT or TRY_CONVERT function with an appropriate datetime style. The CAST function can convert built-in and collection-typed values into other built-in or collection typed values. CAST can convert a date or other unnamed operand (or a nested table or other named collection) into a type-compatible datatype or named collection.
It is internally stored in bytes with each byte storing different components of the datetime value. If you want to display, use TO_CHAR with proper FORMAT MODEL. In the preceding example , TO_DATE converts from text to DATE, and CAST converts from DATE to TIMESTAMP WITH LOCAL TIME ZONE, interpreting the date in the session time zone (SESSIONTIMEZONE). I’ll explain how to use the TO_ DATE function in this article.
TO_CHAR (datetime) converts a datetime or interval value of DATE , TIMESTAMP, TIMESTAMP WITH TIME ZONE, or TIMESTAMP WITH LOCAL TIME ZONE datatype to a value of VARCHARdatatype in the format specified by the date format fmt.