SStrong
(Sophie Strong)
1
我尝试按照下面的链接自行解决,但无法足够快地完成。
我只想计算主题创建日期和今天的日期之间的差值,以便能够说“这个主题已经存在 6 天了”。
这是我正在使用的两个字段:
to_char(date_trunc(‘DAY’, t.created_at)::date,‘DD/MM/YYYY’) AS “主题创建日期”,
to_char(date_trunc(‘DAY’, now())::date,‘DD/MM/YYYY’) AS “今天日期”
PostgreSQL: Documentation: 9.6: Date/Time Functions and Operators
谢谢。
我认为你可以将其简化为:
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 个赞
system
(system)
关闭
4
This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.