MySQL Using a string column with date text as a date field

后端 未结 3 1889
刺人心
刺人心 2020-12-10 22:25

I am doing a database migration and I currently have a string column with dates (versus having the optimal datetime field set for these). Is there a function I can call in M

3条回答
  •  庸人自扰
    2020-12-10 23:05

    SELECT  *
    FROM    mytable
    WHERE   CAST(mydatefield AS DATETIME) >= CAST('2009-01-01' AS DATETIME)
    

    If your dates are in some weird format that MySQL does not understand, use STR_TO_DATE:

    SELECT  *
    FROM    mytable
    WHERE   STR_TO_DATE(mydatefield, '%Y, %d %m') >= STR_TO_DATE('2009, 01 01', '%Y, %d %m')
    

提交回复
热议问题