Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to convert a string date to date format in oracle10g

My date value is stored as varchar2 and the value is 15/August/2009,4:30 PM, how to convert this to a proper date format like DD-MM-YYYY.

like image 786
leelavinodh Avatar asked Dec 03 '11 08:12

leelavinodh


People also ask

How do I convert a string to a date in SQL Developer?

SELECT TO_DATE('2015/05/15 8:30:25', 'YYYY/MM/DD HH:MI:SS') FROM dual; This would convert the string value of 2015/05/15 8:30:25 to a date value.

How do you convert a string to a date in Javascript?

Use the Date() constructor to convert a string to a Date object, e.g. const date = new Date('2022-09-24') . The Date() constructor takes a valid date string as a parameter and returns a Date object. Copied! We used the Date() constructor to convert a string to a Date object.


2 Answers

You can convert a string to a DATE using the TO_DATE function, then reformat the date as another string using TO_CHAR, i.e.:

SELECT TO_CHAR(
         TO_DATE('15/August/2009,4:30 PM'
                ,'DD/Month/YYYY,HH:MI AM')
       ,'DD-MM-YYYY')
FROM DUAL;

15-08-2009

For example, if your table name is MYTABLE and the varchar2 column is MYDATESTRING:

SELECT TO_CHAR(
         TO_DATE(MYDATESTRING
                ,'DD/Month/YYYY,HH:MI AM')
       ,'DD-MM-YYYY')
FROM MYTABLE;
like image 127
Jeffrey Kemp Avatar answered Sep 20 '22 18:09

Jeffrey Kemp


You need to use the TO_DATE function.

SELECT TO_DATE('01/01/2004', 'MM/DD/YYYY') FROM DUAL;
like image 25
PenFold Avatar answered Sep 17 '22 18:09

PenFold