如何将字符串str='2008-04-23 12:00:00'转换为datetime的str='2008-04-23 12:00:00'

解决方案 »

  1.   

    mysql> set @str='2008-04-23 12:00:00';
    Query OK, 0 rows affected (0.00 sec)mysql> SELECT CAST(@str AS DATETIME);
    +------------------------+
    | CAST(@str AS DATETIME) |
    +------------------------+
    | 2008-04-23 12:00:00    |
    +------------------------+
    1 row in set (0.01 sec)
      

  2.   

    按楼上的办法就可以了。如果不放心可以用 STR_TO_DATE(str,format) 这个函数来转换其它格式的字符串。