Jeffrey_Rodriguez_418
Jeffrey_Rodriguez_418

Reputation: 23

SQL Cast / Conversion Varchar to Date

I'm trying to convert a "date" column saved as varchar with the following format : 'March 15, 2014' into a date type so that I can then order the entries by date in the next step.

So far I've tried this :

select cast( `date` as date) from Kampf

which yields the result "Incorrect datetime value: 'March 15, 2014'"

as well as

select CONVERT(date, `date`, 101) from Kampf

which just gives me this syntax error

"SQL-Fehler [1064] [42000]: (conn=103554) You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'date, 101) from Kampf (conn=103554) You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'date, 101) from Kampf (conn=103554) You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'date, 101) from Kampf You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'date, 101) from Kampf You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'date, 101) from Kampf You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'date, 101) from Kampf LIMIT 0, 200' at line 1 You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'date, 101) from Kampf LIMIT 0, 200' at line 1 "

Does anyone have an idea how to solve this ?

Upvotes: 1

Views: 1607

Answers (1)

Gordon Linoff
Gordon Linoff

Reputation: 1269923

In MariaDB, you would use str_to_date():

select str_to_date('March 15, 2014', '%M %d, %Y')

The use of convert() that you are attempting is SQL Server-specific syntax.

Upvotes: 1

Related Questions