Other related articles:

Recently viewed articles:

SQL TO_DATE Function

SQL TO_DATE function converts a selected string to a SQL DATE format used by database. The string may be of any data type, but must conform to a valid SQL date format when converted to a date. SQL TO_DATE function consists of two parameters, character string and
SQL Date format string. The character string parameter represents the string that is to be matched, while the date format string represents the format of input string which has to be converted into DATE type data result.


The following SQL TO_DATE function query will convert '8-Dec-2005' to date format.

SELECT TO_DATE('8-Dec-2005', 'dd-mon-yyyy') from dual;

sql to_date image1

Note: DUAL is a dummy table used by Oracle. The format picture ('dd-mon-yyyy') tells Oracle the SQL Date format of input data string. The function converts the first quoted string into a date, using as a definition the second quoted string

Example 2:
In following SQL TO_DATE function example, notice the change in sql date format picture to reflect format of input string:

SELECT TO_DATE(‘28-08-2010’,’dd-mm-yyyy’) from dual;

sql to_date image2

The date format picture is composed of sql date format elements which are discussed in detail in following topic:

Date Format Element