Mysql: converting date fro 'dd/mm/yyyy' to 'yyyymmdd'

前端 未结 1 718
走了就别回头了
走了就别回头了 2021-01-18 12:17

Im working on a database that store dates in a varchar(10) mysql field (so sad).

I can not alter the database structure (im building a small plug-in), b

相关标签:
1条回答
  • 2021-01-18 12:47

    What about using str_to_date() to create a date from your format?

    EDIT after reading your comment, I created a table like yours:

    mysql> SELECT fid, fdate FROM test;
    +------+------------+
    | fid  | fdate      |
    +------+------------+
    |    1 | 10/9/2010  | 
    |    2 | 17/9/2010  | 
    |    3 | 19/09/2010 | 
    +------+------------+
    

    and then did

    mysql> SELECT fid FROM test WHERE STR_TO_DATE(fdate, '%d/%m/%Y') <= DATE_ADD(NOW(), INTERVAL 10 DAY);
    +------+
    | fid  |
    +------+
    |    1 | 
    |    2 | 
    +------+
    

    Seems to work. What exactly do you get?

    0 讨论(0)
提交回复
热议问题