Difference between revisions of "Calculate age"

From LemonWiki共筆
Jump to navigation Jump to search
m
 
Line 26: Line 26:
 
<references />
 
<references />
  
[[Category:Excel]] [[Category:MySQL]]
+
[[Category:Excel]] [[Category:MySQL]] [[Category:Time river]]

Latest revision as of 14:01, 10 February 2022

Calculate age in Excel or MySQL

Calculate age in Excel[edit]

If the column value is well-formatted

  • =(TODAY()- BIRTH_DAY)/365[1]
  • =ROUNDDOWN(YEARFRAC(BIRTH_DAY, TODAY(), 1), 0)

Calculate age in MySQL[edit]

SELECT `birth_date`, TIMESTAMPDIFF (YEAR, `birth_date`, CURDATE()) AS age
FROM `my_table` 
WHERE `birth_date` IS NOT NULL

[2]

Challenge of real world data[edit]

The column value is NOT well-formatted such as

  • year only e.g. 2022
  • month & date only e.g. 10-7

References[edit]