In this tutorial we are going to convert string to sql TIMESTAMP using TO_TIMESTAMP function . See the following syntax.
Syntax:
Example:
Output :
See the above exmaple , two parameters passed to TIME_STAMP function . First parameter is string date that we want to convert . Second parameter is the format that our string contains.
For example , if our string date is ‘January 13 2015 10:22:22’ then date format that should be passed to TO_DATE function is ‘MONTH DD YYYY HH:MI:SS’ .
Some date & time formats
Syntax:
SELECT TO_TIMESTAMP('STRING TIMSTAMP' , 'STRING TIMSTAMP FORMAT') AS SYS_DATE FROM DUAL;
SELECT TO_TIMESTAMP('2016/01/26 10:15:48', 'YYYY/MM/DD HH:MI:SS') as TIME_STAMP from DUAL;
Output :
TIME_STAMP |
---|
26-JAN-16 10.15.48.000000000 AM |
See the above exmaple , two parameters passed to TIME_STAMP function . First parameter is string date that we want to convert . Second parameter is the format that our string contains.
For example , if our string date is ‘January 13 2015 10:22:22’ then date format that should be passed to TO_DATE function is ‘MONTH DD YYYY HH:MI:SS’ .
Some date & time 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 |