Birthday age calculations

So I have someone’s birthdate and the current date. Easy to calculate days old but how to convert that to years taking leap years into consideration. Can’t just divide by 365…

Stupid idea…

Substract birthdate (SecondsFrom1970: integer value) to today (SecondsFrom1970: integer value),
Create a brand new date and set the result,
Read the date specs for the # of years, months, days…

btw: what are the API2 specs for date ?

There’s even IntervalValue

var interval as DateInterval = currentDate - birthDate var years as String = "Years: " + interval.Years.ToString var months as String = "Months: " + interval.Months.ToString // etc

Not at computer but something like this should do it. Don’t calculate it yourself, that way lies pain and misery.

Perhaps this would this work for you:

Dim birthday As New Xojo.Core.Date(1955, 2, 24, Xojo.Core.TimeZone.Current) Dim age As Xojo.Core.DateInterval = Xojo.Core.Date.Now - birthday

Try the Beta if you’d like to do this with DateTime.

We have DateDifferenceMBS class for this kind of calculation.

No need for betas, DateTime is in 2019r2.

The problem is not with DateTime but with DateInterval.
You can’t do this with Xojo 2019r2.1

Var age As DateInterval = DateTime.Now - birthday

and it works with the Beta.