0

In one of my DB column i have a string like this

19-Oct-19

i want to change this string to a proper date format like this

19-10-2019  or 19-10-2019

how can i achieve this with sql

2
  • 1
    19-Oct-19 is a good example of an unclear date format. Does the leading 19 mean day or year? Does the ending 19 mean year or day? However, never store dates as strings, use proper date data type instead. Commented Aug 24, 2021 at 9:38
  • yes, I know got the data from some customer and dumped that data directly into the table now trying to convert the same. leading 19 is the year 2019. Commented Aug 24, 2021 at 9:42

1 Answer 1

2

With STR_TO_DATE() you can convert String to Date and with DATE_FORMAT() format your Date value.

select DATE_FORMAT(STR_TO_DATE('19-Oct-19', '%Y-%M-%d'), '%d-%m-%Y');
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.