mysql中from_unixtime - UNIX_TIMESTAMP 格式化时间

时间: 2009-07-12  分类: php+Mysql  收藏

FROM_UNIXTIME是把unix时间戳转换成格式化的日期形式

例如:

SQL> select REG_TIME,LOGON_TIME,LOGOFF_TIME,ONLINE_TIME from user_info_tb where uin=8008123;

REG_TIME LOGON_TIME LOGOFF_TIME ONLINE_TIME
---------- ---------- ----------- -----------
1121441901 1214490692 1214490907      967301

 

mysql> select from_unixtime(1121441901,'%Y%m%d');
+------------------------------------+
| from_unixtime(1121441901,'%Y%m%d') |
+------------------------------------+
| 20050715                           |
+------------------------------------+
1 row in set (0.00 sec)

 

mysql> select from_unixtime(1214490907, '%Y年%m月%d' )

       ->2008年06月26

UNIX_TIMESTAMP()是与之相对正好相反的时间函数

例如:

mysql> SELECT UNIX_TIMESTAMP('2008-06-27');
+------------------------------+
| UNIX_TIMESTAMP('2008-06-27') |
+------------------------------+
| 1214524800                   |
+------------------------------+
1 row in set (0.02 sec)

分享到:

评论

昵 称: