两个日期之间的DATEDIFF

我认为你可以将其简化为:

SELECT 
    t.id AS topic_id,
    CURRENT_DATE - t.created_at::date AS days_old
FROM topics t
ORDER BY t.created_at DESC

还有一个很棒的 reltime$time,你可以用它来给出相对时间(但它更适用于小于 30 天的间隔,否则会显示日期)

SELECT 
    t.id AS topic_id,
    t.created_at AS reltime$time
FROM topics t
ORDER BY t.created_at DESC
1 个赞