下载了一个论坛系统,里面的日期部分的类型都是 int,
给我的感觉像时间戳,比如 select regdate from cdb_members limit 0,1结果是 1173690720请问,mysql有没有什么内置的函数,能够将这个整型转成日期类型,
还是我必须先取到它,然后在我的应用程序中转换,
谢谢。

解决方案 »

  1.   

    mysql> select from_unixtime(1173690720);
    +---------------------------+
    | from_unixtime(1173690720) |
    +---------------------------+
    | 2007-03-12 17:12:00       | 
    +---------------------------+
    1 row in set (0.00 sec)
      

  2.   

    select from_unixtime(1173690720);
    mysq help
    FROM_UNIXTIME(unix_timestamp), FROM_UNIXTIME(unix_timestamp,format) Returns a representation of the unix_timestamp argument as a value in 'YYYY-MM-DD HH:MM:SS' or YYYYMMDDHHMMSS format, depending on whether the function is used in a string or numeric context. The value is expressed in the current time zone. unix_timestamp is an internal timestamp value such as is produced by the UNIX_TIMESTAMP() function. If format is given, the result is formatted according to the format string, which is used the same way as listed in the entry for the DATE_FORMAT() function. mysql> SELECT FROM_UNIXTIME(875996580);
            -> '1997-10-04 22:23:00'
    mysql> SELECT FROM_UNIXTIME(875996580) + 0;
            -> 19971004222300
    mysql> SELECT FROM_UNIXTIME(UNIX_TIMESTAMP(),
        ->                      '%Y %D %M %h:%i:%s %x');
            -> '2003 6th August 06:22:58 2003'Note: If you use UNIX_TIMESTAMP() and FROM_UNIXTIME() to convert between TIMESTAMP values and Unix timestamp values, the conversion is lossy because the mapping is not one-to-one in both directions. For details, see the description of the UNIX_TIMESTAMP() function. 
      

  3.   

    再补充一个有意思的:
    mysql> set timestamp=1173690720;
    Query OK, 0 rows affected (0.05 sec)mysql> select now();
    +---------------------+
    | now()               |
    +---------------------+
    | 2007-03-12 17:12:00 |
    +---------------------+
    1 row in set (0.06 sec)mysql> quit
    Bye运行完之后立刻退出。