Datediff between two dates

I think you could simplify that to something like:

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

There’s also a nifty reltime$time you can use to give relative time (though it’s more useful for intervals of less than 30 days or it gives dates instead)

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