|
Post by Roger Cabo on Nov 17, 2022 21:16:01 GMT 1
Hi everyone, I like to find out how old someone is currently. The given birthday, lets say 25.11.2000 and the current day is the 17.11.2022. currently hes 21 years old. But at the 25.11.2022 he became 22. I have a solution that's a bit quirky. Like to try it by your own? I's not that trivial. But if you have the right systematic solution, it works. At first I tried to calculate by days, but this cause an issue. You have to find out what leap years over the whole time exist. My solution is not far away :-)
MsgBox GetAgeFromBirthDay(CDate("18.11.2000 00:00:00"), Now)
Function GetAgeFromBirthDay(d1 As Date, d2 As Date) As Int // return age between to dates Dim _dayDiff% = Day(d1) - 1 Return Floor((DateDiff("m", d1 - _dayDiff, (d2 - _dayDiff))) / 12) Return
|
|
webu
Full Member
Posts: 149
|
Post by webu on Nov 17, 2022 22:34:12 GMT 1
No Problem:
Message "1: " & age(Date, #16.11.2000#) Message "2: " & age(Date, #17.11.2000#) Message "3: " & age(Date, #18.11.2000#) Function age(dat As Date, birth As Date) As Int Return Year(dat) - Year(birth) + (Format(dat, "mmdd") < Format(birth, "mmdd"))
|
|
|
Post by Roger Cabo on Nov 18, 2022 0:19:30 GMT 1
Yes good! your's is easier my solution is already written under my original text if you press CTRL+A you will see it.
|
|
webu
Full Member
Posts: 149
|
Post by webu on Nov 20, 2022 14:36:22 GMT 1
For both solutions it is important that the parameter for the birthday is exactly fixed. There must be no paramter swapping. Therefore I call it 'birth'.
Bei beiden Lösungen ist es wichtig, dass der Parameter für den Geburtstag exakt feststeht. Es darf keine Paramter-Vertauschung stattfinden. Daher nenne ich ihn auch 'birth'.
|
|