1

我的网站上有一个评论区,每条评论以正常日期格式(2012 年 11 月 5 日)发布时都会显示...但我想显示“1 天前”甚至“3 小时前”正常格式......这是我到目前为止的内容:

SELECT p.poll_id, p.title, date_format(c.posted, '%D %b %y') as time, COUNT( c.poll_id ) AS count, u.username
FROM users AS u
JOIN polls AS p ON u.user_id = p.user_id
LEFT JOIN comment AS c ON p.poll_id = c.poll_id
LIMIT 5 
4

1 回答 1

2

使用日期差异函数 评估日期差异

SELECT p.poll_id, p.title,  DATEDIFF(NOW(), c.posted) AS daysold, COUNT( c.poll_id ) AS   count, u.username
  FROM users AS u
  JOIN polls AS p ON u.user_id = p.user_id
  LEFT JOIN comment AS c ON p.poll_id = c.poll_id
  LIMIT 5
于 2012-11-05T18:15:21.850 回答