mysql查询时间字段转换为几天前几小时前几分钟前

阅读更多

SELECT
CASE
WHEN TIMESTAMPDIFF(DAY, publish_time,NOW()) > 0
THEN CONCAT(TIMESTAMPDIFF(DAY, publish_time,NOW()),'天前')

WHEN TIMESTAMPDIFF(HOUR, publish_time,NOW()) > 0
THEN CONCAT(TIMESTAMPDIFF(HOUR, publish_time,NOW()),'小时前')

WHEN TIMESTAMPDIFF(MINUTE, publish_time,NOW()) > 0
THEN CONCAT(TIMESTAMPDIFF(MINUTE, publish_time,NOW()),'分前')
END  AS TIME
 
FROM  表名

你可能感兴趣的:(mysql查询时间字段转换为几天前几小时前几分钟前)