美文网首页
from_unixtime, unix_timestamp

from_unixtime, unix_timestamp

作者: whenitsallover | 来源:发表于2018-09-27 10:34 被阅读0次

FROM_UNIXTIME(unix_timestamp)为MySQL里的时间函数。

from_unixtime 将数据库中的时间戳转换成对应的时间格式:

select count(*) from table_name where from_unixtime(time/1000,'%Y-%m-%d') bewteen
'2019-01-01' and '2019-01-02';
time 为时间戳格式

※ from_unixtime 会使time字段的索引失效。

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

select unix_timestamp('2018-01-01') from table_name limit 1;

将返回一个时间戳,unix_timestamp() 不会让time字段的索引失效,因而效率更高。

相关文章

网友评论

      本文标题:from_unixtime, unix_timestamp

      本文链接:https://www.haomeiwen.com/subject/ttzsoftx.html