Calculate age

From LemonWiki共筆
Revision as of 14:01, 10 February 2022 by Unknown user (talk)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search
The printable version is no longer supported and may have rendering errors. Please update your browser bookmarks and please use the default browser print function instead.

Calculate age in Excel or MySQL

Calculate age in Excel

If the column value is well-formatted

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

Calculate age in MySQL

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

The column value is NOT well-formatted such as

  • year only e.g. 2024
  • month & date only e.g. 03-29

References