# Display a date calculation?

**URL:** <https://community.glideapps.com/t/display-a-date-calculation/80105>\
**Category:** Ask for Help\
**Created:** [February 17, 2025, 7:06am UTC](https://community.glideapps.com/t/display-a-date-calculation/80105 "2025-02-17T07:06:02Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![SageCat](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/sagecat/32/85273_2.png) [@SageCat](https://community.glideapps.com/u/SageCat)\
**Post date:** [February 17, 2025, 7:06am UTC](https://community.glideapps.com/t/display-a-date-calculation/80105/1 "2025-02-17T07:06:02Z")

</div>

Hi again.

Is it possible to have a date calculation field? For example, an age field which is automatically calculated from a Birth Date field and today? I assume it would likely be a column in the table which the front end would then display but I’m not sure how to go about doing this.

Thanks again

---

<div class="post-metadata">

**Author:** ![Darren\_Murphy](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/darren_murphy/32/47326_2.png) [@Darren\_Murphy](https://community.glideapps.com/u/Darren_Murphy)\
**Post date:** [February 17, 2025, 7:25am UTC](https://community.glideapps.com/t/display-a-date-calculation/80105/2 "2025-02-17T07:25:18Z")

</div>

Use a Math column with the following formula:

```auto
Trunc((Now-DOB)/365.25)

```

In the above, you have two replacements:

- `Now` is a special value representing the current date/time
- `DOB` is the column that contains the birthdate.

Here is how it looks:

 ![CleanShot 2025-02-17 at 15.24.11@2x](https://us1.discourse-cdn.com/flex002/uploads/glideapps/original/3X/7/b/7ba53a71882221a59b85a4cad24540deb47f508c.png)

 ![CleanShot 2025-02-17 at 15.24.37@2x](https://us1.discourse-cdn.com/flex002/uploads/glideapps/original/3X/b/6/b67c192f06d7547100b5f412990a0f3455ca7b98.png)

The calculation isn’t precise, but should be good enough for this purpose.

---

<div class="post-metadata">

**Author:** ![SageCat](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/sagecat/32/85273_2.png) [@SageCat](https://community.glideapps.com/u/SageCat)\
**Post date:** [February 17, 2025, 7:27am UTC](https://community.glideapps.com/t/display-a-date-calculation/80105/3 "2025-02-17T07:27:57Z")

</div>

Thanks for this. I figured it was tucked somewhere in there but I wasn’t sure. I actually need it to show years months and days. Is that possible? It might be 0 years 4 months and 3 days.

---

<div class="post-metadata">

**Author:** ![SageCat](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/sagecat/32/85273_2.png) [@SageCat](https://community.glideapps.com/u/SageCat)\
**Post date:** [February 17, 2025, 7:29am UTC](https://community.glideapps.com/t/display-a-date-calculation/80105/4 "2025-02-17T07:29:05Z")

</div>

And thank you again, Darren, for all this help you are giving! You’re amazing with your knowledge on this and your speed in helping! Thank you so much!

---

<div class="post-metadata">

**Author:** ![Darren\_Murphy](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/darren_murphy/32/47326_2.png) [@Darren\_Murphy](https://community.glideapps.com/u/Darren_Murphy)\
**Post date:** [February 17, 2025, 7:34am UTC](https://community.glideapps.com/t/display-a-date-calculation/80105/5 "2025-02-17T07:34:54Z")

</div>

> [@SageCat](#):
>
> I actually need it to show years months and days. Is that possible? It might be 0 years 4 months and 3 days.

Okay, that’s a little more complicated, and there are a few ways to do it. Most involve several columns to extract the separate parts and then join them back together with a template column.

In this case I would probably use a JavaScript column and write a code snippet to do the heavy lifting. Don’t have time to give you an example now, but if nobody else offers up a solution I can take a look a little bit later.

---

<div class="post-metadata">

**Author:** ![Darren\_Murphy](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/darren_murphy/32/47326_2.png) [@Darren\_Murphy](https://community.glideapps.com/u/Darren_Murphy)\
**Post date:** [February 17, 2025, 8:03am UTC](https://community.glideapps.com/t/display-a-date-calculation/80105/6 "2025-02-17T08:03:13Z")

</div>

@SageCat - here we go…

```auto
let birthDate = new Date(p1);
let today = new Date();

let years = today.getFullYear() - birthDate.getFullYear();
let months = today.getMonth() - birthDate.getMonth();
let days = today.getDate() - birthDate.getDate();

if (days < 0) {
    months--;
    let lastMonth = new Date(today.getFullYear(), today.getMonth(), 0);
    days += lastMonth.getDate();
}

if (months < 0) {
    years--;
    months += 12;
}

return `${years} years, ${months} months, ${days} days`

```

 ![CleanShot 2025-02-17 at 16.02.42@2x](https://us1.discourse-cdn.com/flex002/uploads/glideapps/original/3X/1/d/1dbfdfb11734e30c75f1d5712737738c38aba2c1.png)

 ![CleanShot 2025-02-17 at 16.02.20@2x](https://us1.discourse-cdn.com/flex002/uploads/glideapps/original/3X/d/2/d2b3fe38a1f0473ad4af4cef8a416423ea5bb46a.png)

---

<div class="post-metadata">

**Author:** ![SageCat](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/sagecat/32/85273_2.png) [@SageCat](https://community.glideapps.com/u/SageCat)\
**Post date:** [February 17, 2025, 9:22am UTC](https://community.glideapps.com/t/display-a-date-calculation/80105/7 "2025-02-17T09:22:52Z")

</div>

Oh wow. Thank you. I will have a go getting this to work.

---

<div class="post-metadata">

**Author:** ![SageCat](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/sagecat/32/85273_2.png) [@SageCat](https://community.glideapps.com/u/SageCat)\
**Post date:** [February 17, 2025, 9:39am UTC](https://community.glideapps.com/t/display-a-date-calculation/80105/8 "2025-02-17T09:39:34Z")

</div>

That works fantastically! Thank you so much!

---

<div class="post-metadata">

**Author:** ![system](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/system/32/53398_2.png) [@system](https://community.glideapps.com/u/system)\
**Post date:** [February 24, 2025, 9:40am UTC](https://community.glideapps.com/t/display-a-date-calculation/80105/9 "2025-02-24T09:40:17Z")

</div>

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