Code: Select all
DOB := "02/15/1998" ; input the birthdate (the format is MM/DD/YYYY)
StringSplit, dates, DOB, `/ ; chops up DOB
MAct:= A_MM ; setting variable for current month
AAct:= A_YYYY ; setting variable for current year
DAct:= A_DD ; setting variable for current day
MNac:= dates1 ; setting variable for birth month
ANac:= dates3 ; setting variable for birth year
DNac:= dates2 ; setting variable for birth day
sleep, 10 ; chilling for a sec
If (MAct<MNac)
{
Age:=AAct-ANac-1
}
If (MAct=MNac and DAct<DNac)
{
Age:=AAct-ANac-1
}
If (MAct=MNac and DAct>=DNac)
{
Age:=AAct-ANac
}
If (MAct>MNac)
{
Age:=AAct-ANac
}
sleep, 100 ; chilling for a sec
MsgBox, The age is %age%
A little while ago I needed a way to calculate age off of knowing a birthdate. Most documentation I found wasn't really working in my case, so after working through what was best for me, I wanted to turn around and share it to hopefully help someone else down the road. Probably not the most elegant way of doing things and it could be reduced somewhat but I think it is stable and pretty easy to understand