Difference between revisions of "Calculate Age from Date of Birth"

From SmartWiki
Jump to: navigation, search
 
 
(4 intermediate revisions by 2 users not shown)
Line 2: Line 2:
  
  
To display a current age you should create a [[Custom Field Type: Special – Calculated Value|Calculated Value Custom Field]] with the following  
+
To display a current age you should create a [[Custom Field Type: Special – Calculated Value|Calculated Value Custom Field]] with the following expression:
 
  calage([date of birth])
 
  calage([date of birth])
 +
:where ''date of birth'' is the name of the field that contains the date. It must be present and visible on the current page for this function to work.
  
'''Note:''' the ''calage'' function actually calculates the number of full years between the current date and the date included in the function.
 
  
[[Category:JavaScript Examples]]
+
To display number of years and months between the current date and the date included in the function as a floating point you should create a [[Custom Field Type: Special – Calculated Value|Calculated Value Custom Field]] with the following expression:
 +
calage([date of birth],1)
 +
 
 +
 
 +
To display the number of years and months between the current date and the date included in the function as the string "X years and Y months" you should create a [[Custom Field Type: Special – Calculated Value|Calculated Value Custom Field]] with the following expression:
 +
calage([date of birth],2)
 +
 
 +
 
 +
 
 +
[[Category:JavaScript]][[Category:Date Formats]]

Latest revision as of 15:58, 25 September 2017

There is a system function called calage which can be used to calculate a current age when given the Date of Birth:


To display a current age you should create a Calculated Value Custom Field with the following expression:

calage([date of birth])
where date of birth is the name of the field that contains the date. It must be present and visible on the current page for this function to work.


To display number of years and months between the current date and the date included in the function as a floating point you should create a Calculated Value Custom Field with the following expression:

calage([date of birth],1)


To display the number of years and months between the current date and the date included in the function as the string "X years and Y months" you should create a Calculated Value Custom Field with the following expression:

calage([date of birth],2)