Using TO_DATE oracle function we can convert string date to sql date . See the following syntax.
Syntax:
Example:
Output :
See the above exmaple , two parameters passed to TO_DATE function . First parameter is string date that we want to convert . Second parameter is the date format of string .
For example , if our string date is ‘January 13 2015’ then date format that should be passed to TO_DATE function is ‘MONTH DD YYYY’ .
Some date formats
Syntax:
SELECT TO_DATE('STRING DATE' , 'STRING DATE FORMAT') AS SYS_DATE FROM DUAL;
SELECT TO_DATE('01/08/2015' , 'DD/MM/YYYY') from DUAL;
Output :
SYSDATE |
---|
01-AUG-15 |
See the above exmaple , two parameters passed to TO_DATE function . First parameter is string date that we want to convert . Second parameter is the date format of string .
For example , if our string date is ‘January 13 2015’ then date format that should be passed to TO_DATE function is ‘MONTH DD YYYY’ .
Some date formats
FORMAT | DESSCRIPTION |
---|---|
DD | Represents day number in a month. |
DDD | Represents day number in a year[1-366] (for exmaple :091) |
D | Gives day number in a week[1-7] |
DAY | Gives day name Ex : sunday |
FMDAY | Gives day name without trailing spaces |
MM | Gives month number |
MON | Gives First three letters of month . Ex :FEB |
MONTH | Gives complete month name with trailing spaces. |
FMMONTH | Gives complete month without trailing spaces. |
YY | Gives last two digits of year |
YYYY | Gives year number. |
YEAR | Gives year in word format. Ex: TWENTY SIXTEEN |