Converting Date Formats

The conversion of dates takes place for any number of reasons. Conversions are mainly used to alter the data type of values defined as DATETIME values.

Typical reasons for date conversions are

  • To compare date values of different data types

  • To format a date value as a character string

  • To convert a character string into a date format

The ANSI CAST operator is used to convert data types into other data types. The basic syntax is


Individual implementations of SQL may use another function instead of CAST. For example, in Oracle, the TO_DATE function is used to convert a character string to ...

Get Sams Teach Yourself SQL in 21 Days, Fourth Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.