ageofbirthday

by Tim C. Lueth, SG-Lib Toolbox: SolidGeometry 5.6 - Auxiliary function
Introduced first in SolidGeometry 5.2, Creation date: 2022-09-02, Last change: 2025-09-15

returns tge age in years of a birtday string and an optional reference date string



See Also:

Example Illustration

 missing image of ageofbirthday(day,refd)

Syntax

[age,chkd,refd]=ageofbirthday(day,[refd])

Input Parameter

day: string of birthday, such as '30.11.1965)
refd: string of refence date, such as {1.6.2016'; default is now

Output Parameter

age: age in years
chkd: numerical value of date
refd: numerical value of reference date

Examples


ageofbirthday('30.11.1965')
ageofbirthday('30.11.1965','1.10.1984')
ageofbirthday('30.11.1965','3.2.1989')
ageofbirthday('30.11.1965','3.2.1993')
ageofbirthday('30.11.1965','2.7.1997')
ageofbirthday('30.11.1965','10.04.2010') % 1st election of Dean
ageofbirthday('30.11.1965','21.10.2010') % Birthday of SG-Lib




Copyright 2022-2025 Tim C. Lueth. All rights reserved. The code is the property of Tim C. Lueth and may not be redistributed or modified without explicit written permission. This software may be used free of charge for academic research and teaching purposes only. Commercial use, redistribution, modification, or reverse engineering is strictly prohibited. Access to source code is restricted and granted only under specific agreements. For licensing inquiries or commercial use, please contact: Tim C. Lueth

Algorithm (Workflow)

This function calculates the age in years based on a given birthday string and an optional reference date string. It is part of the SolidGeometry library.

Input Parameters

Output Results

Algorithm Steps

  1. Set the reference date (refd) using the function getfuncparams. If not provided, use the current date.
  2. If refd is a string and contains 'tim', set refd to '30.11.1965'.
  3. Convert refd to a numerical date using datenum and datetime.
  4. Convert the birthday (day) to a numerical date using datenum and datetime.
  5. Calculate the age in years as (refd - chkd) / 365.25.
  6. If the age is positive, calculate the years and months. Use floor for years and round for months.
  7. If the age is negative, use ceil for years and round for months.
  8. If no output is requested, print the age in years and months using dbprintf.
  9. If output is requested, return the age.
Algorithm explaination created using ChatGPT on 2025-08-19 06:53. (Please note: No guarantee for the correctness of this explanation)

Last html export of this page out of FM database by TL: 2025-09-21