SOLVED

Date calculation on SharePoint lists between today and a birthdate

Brass Contributor

Hi I've tried to calculate the age of a person based on 2 columns (NO success at all) on a SharePoint list.

 

Therefore I need help, from the ground:

 

  1. Birthday column is a DATE column
  2. Today's date - how do I create that?
  3. Age in years (no decimals) between column 1 and 2 - what column type and calculation should I use?

Thanks.

9 Replies
best response confirmed by jensjakobsen1966 (Brass Contributor)
Solution

@jensjakobsen1966 there are a couple of ways to do this. One is with a flow in Power Automate that runs once a day and does the calculation. Another is to have a number column and format it with JSON as follows:

 

{
  "$schema": "https://developer.microsoft.com/json-schemas/sp/column-formatting.schema.json",
  "elmType": "div",
  "txtContent": "=floor((Number(@now)-Number([$Birthday]))/(1000*60*60*24*12)/365*12)"
}

 

The result is:

 

age.png

 

 

Rob
Los Gallardos
Intranet, SharePoint and Power Platform Manager (and classic 1967 Morris Traveller driver)

Such a beautiful solution - THANK YOU!

:)

Hi again @RobElliott - I believe there's an error. And I'm sorry to bother you again.

Whenever a person has his/hers birthday within January to July, the formula will round up the age, even though the person has not yet had their birthday.

 

 

@jensjakobsen1966 that's strange and I can't reproduce it; as you can see from the image below, there is no incorrect rounding of the ages on my list:

 

age2.png

 

Rob
Los Gallardos
Intranet, SharePoint and Power Platform Manager (and classic 1967 Morris Traveller driver)

@RobElliott - thank you for revisiting this subject.

 

I totally agree with you, and I struggle to explain the error. Can it be something to do with the regional setting for the SharePoint? I've uploaded my settings, if this can shed any light.

 

Don't do anything, please, I'm happy to use it, even though my results differ a bit.

Hi,

How do you do this using PowerAutomate?

That might because of leap years, try to add .25 to 365 at the end the code
i.e: /365.25*12

@jensjakobsen1966 

@RobElliott 

I used the exact same thing but every result returned 53. Are there some other settings I may have missed?

 

Bo_Li_Cheng_0-1673322827474.png

 

1 best response

Accepted Solutions
best response confirmed by jensjakobsen1966 (Brass Contributor)
Solution

@jensjakobsen1966 there are a couple of ways to do this. One is with a flow in Power Automate that runs once a day and does the calculation. Another is to have a number column and format it with JSON as follows:

 

{
  "$schema": "https://developer.microsoft.com/json-schemas/sp/column-formatting.schema.json",
  "elmType": "div",
  "txtContent": "=floor((Number(@now)-Number([$Birthday]))/(1000*60*60*24*12)/365*12)"
}

 

The result is:

 

age.png

 

 

Rob
Los Gallardos
Intranet, SharePoint and Power Platform Manager (and classic 1967 Morris Traveller driver)

View solution in original post