Lists Formulas For Calculate Age From Date of Birth

Occasional Contributor

Hi,

 

In the below list I have a column labeled 'DoB (Date of Birth)' and another column labeled 'Age". How do I make the calculated age based on the date of birth automatically populate the 'age' field?

 

Thanks

 

List.png

5 Replies

@jinibob   You can do this with JSON column formatting.  I tested this solution by @RobElliott and it worked perfectly.   Date calculation on SharePoint lists between today and a birthdate - Microsoft Tech Community  

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

 

Hi,

Thanks for the info. Where do I need to paste the above code that you have kindly provided?

Thanks
Go to your column-> select the drop down (arrow pointing downwards) -> Column settings -> Format this column -> in popped up window, under format columns, select Advanced mode link at the bottom -> copy paste the json, Preview and Save

@jinibob Hi there,  here are some screen shots if it helps.

 

From the column view:

PamDeGraffenreid_4-1660094308608.png

 

Select Column and click Advanced formatting

PamDeGraffenreid_7-1660094474879.png

 

Then paste in the snippet  

PamDeGraffenreid_6-1660094394981.png

 

Sounds like you are just getting into column formatting with JSON- so exciting.   Here's a great resource-  List-Formatting/view-samples at master · pnp/List-Formatting · GitHub

 

 
 

 

 

 

@jinibob Addition to above all responses, Here's Microsoft official documentation on this topic which might help you:

Use column formatting to customize SharePoint 

 

Note: column (JSON) formatting only customizes display of list view to show the formatted value. It does not store/save actual value in column. So, you will not be able to apply sort/filter based on these values in list view.


Please click Mark as Best Response & Like if my post helped you to solve your issue. This will help others to find the correct solution easily. It also closes the item. If the post was useful in other ways, please consider giving it Like.