skip to Main Content

Im trying to convert a date in the form either dd/mm/yy
with

from concertlistts as c
SELECT STR_TO_DATE(str(c.Date)), "%e, %m, %y"));

but when I try to run it it says syntax errors

How do I fix this

I’ve tried

from concertlistts as c
SELECT STR_TO_DATE(str(c.Date)), "%e, %m, %y"));

2

Answers


  1. Clauses of the SQL SELECT statement need to be in the right order. SELECT comes before FROM. Study the proper syntax in the manual.

    MySQL has no function STR(), and you don’t need it in this case.

    If your date string has slashes (/), then use the same character in your format string, not commas (,).

    Here’s a demo I tested with MySQL 8.4.3:

    mysql> create table concertlistts ( date varchar(20));
    Query OK, 0 rows affected (0.03 sec)
    
    mysql> insert into concertlistts values ('18/11/24');
    Query OK, 1 row affected (0.00 sec)
    
    mysql> select str_to_date(date, '%e/%m/%y') as date from concertlistts;
    +------------+
    | date       |
    +------------+
    | 2024-11-18 |
    +------------+
    
    Login or Signup to reply.
  2. Below is the correct syntax.

    SELECT STR_TO_DATE(c.date, '%d/%m/%y') AS parsed_date
    FROM concertlistts AS c;
    

    https://dbfiddle.uk/xkWalE9c

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search