Home > Enterprise >  How to convert "Wed Jan 26 2022" to date in sql?
How to convert "Wed Jan 26 2022" to date in sql?

Time:01-28

I have varchar like this "Wed Jan 26 2022" I need to convert this to date in sql. How can i do this

CodePudding user response:

for Sql Server:

convert(date, substring('Wed Jan 26 2022',5,11),9)

we ignore the Day name (superfluous), and convert the rest using format 9 indicating Mon dd yyyy format.

CodePudding user response:

SQL*plus server (Here's my code) - If I am right, you want such type of string which is an invalid one to convert that into a valid one so that you can store valid data into the database. then this code you can use->

SELECT TO_DATE('WED JAN 26 2022','DY MON DD YYYY')FROM DUAL;

(Explanation)-> Code will convert invalid date datatype to a valid date data type which is used in Oracle(SQL).

DY = Abbreviated Week Day

DD = Month day indicator

MON = Abbreviated month

YYYY = Four-digit year indicator

  •  Tags:  
  • Related