# Datediff between two dates

**URL:** https://meta.discourse.org/t/datediff-between-two-dates/323799
**Category:** Data & reporting
**Created:** [August 28, 2024, 3:35pm UTC](https://meta.discourse.org/t/datediff-between-two-dates/323799 "2024-08-28T15:35:06Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![SStrong](https://avatars.discourse-cdn.com/v4/letter/s/ee7513/32.png) [@SStrong](https://meta.discourse.org/u/SStrong)
#### Post date: [August 28, 2024, 3:35pm UTC](https://meta.discourse.org/t/datediff-between-two-dates/323799/1 "2024-08-28T15:35:06Z")

</div>

I’ve tried following the below link to work this out myself but cannot quickly enough

What I would simply like to do is a date diff between topic created date and today’s date to be able to say “this topic is 6 days old”

These are the two fields I am working with:

to\_char(date\_trunc(‘DAY’, t.created\_at)::date,‘DD/MM/YYYY’) AS “Topic created date”,  
to\_char(date\_trunc(‘DAY’, now())::date,‘DD/MM/YYYY’) AS “Today date”

[PostgreSQL: Documentation: 9.6: Date/Time Functions and Operators](https://www.postgresql.org/docs/9.6/functions-datetime.html)

Thanks

---

<div class="post-metadata">

### Author: ![JammyDodger](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/jammydodger/32/254611_2.png) [@JammyDodger](https://meta.discourse.org/u/JammyDodger)
#### Post date: [August 28, 2024, 4:12pm UTC](https://meta.discourse.org/t/datediff-between-two-dates/323799/2 "2024-08-28T16:12:32Z")

</div>

> [@SStrong](#):
>
> What I would simply like to do is a date diff between topic created date and today’s date to be able to say “this topic is 6 days old”

I think you could simplify that to something like:

```sql
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)

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

```

---

<div class="post-metadata">

### Author: ![SStrong](https://avatars.discourse-cdn.com/v4/letter/s/ee7513/32.png) [@SStrong](https://meta.discourse.org/u/SStrong)
#### Post date: [August 29, 2024, 12:31pm UTC](https://meta.discourse.org/t/datediff-between-two-dates/323799/3 "2024-08-29T12:31:51Z")

</div>

Excellent - thanks so much for this

---

<div class="post-metadata">

### Author: ![system](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/system/32/443519_2.png) [@system](https://meta.discourse.org/u/system)
#### Post date: [September 28, 2024, 12:32pm UTC](https://meta.discourse.org/t/datediff-between-two-dates/323799/4 "2024-09-28T12:32:39Z")

</div>

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
