Param
Param

Reputation: 55

String To Date Conversion in Mysql

I have a column values like 20150921. I want to convert this string value to a specified date format like 2015-09-21 in mysql.

Upvotes: 1

Views: 60

Answers (2)

Anshuman Chatterjee
Anshuman Chatterjee

Reputation: 962

I am able to run this query on my MySql 5.6.

SELECT DATE('20150921');

So i believe, this should work directly DATE(colStringDate)

Upvotes: 0

Rahul Tripathi
Rahul Tripathi

Reputation: 172638

Try this:

date_format(str_to_date('20150921', '%Y%m%d'),'%Y-%m-%d')

SQL FIDDLE DEMO

(Assuming that you want your date format to be in YYYY-MM-DD format)

Upvotes: 2

Related Questions