How to calculate age based on Date of Birth (Date field)

How to calculate age based on Date of Birth (Date field)

  
Does anybody know a way to calculate an age?

I have a DateofBirth field (date Type) how can I create the age based of today’s current date.

I have tried

CurrDate() - GetStudent.List.Current.Students.DateofBirth / 365.25

In the expression editor… but the editor does not like it… it gives me the following “ Invalid Data Type
Incompatible data types in / operator ('Date', 'Decimal').”

Any ideas how to get this to work?

Thanks

Dan

Hi Dan,

You can built-in-function 'DiffDays':  DiffDays( GetStudent.List.Current.Students.DateofBirth, CurrDate() ) / 365.25

The error you're getting is because you can't divide a DateTime type (GetStudent.List.Current.Students.DateofBirth) by a decimal (365.25).


I suggest you to check the other existing built-in-functions, in Service Studio expression editor or in the online help.


Regards,
João Portela

Hi,

I forgot to say that if you're calculating the age (integer value) of a person, the best way to do it is something like:

if (  ( month( CurrDate()) > month( DateofBirth)) or
   ( month( CurrDate()) = month( DateofBirth) and day( CurrDate()) >= day( DateofBirth)  ) ,
  
   // birthday already passes this year
   year( CurrDate()) -year ( DateofBirth) ) ,
  // birthday still to come
   year( CurrDate()) -year ( DateofBirth) ) -1)


Hope that this help.

Regards,
João Portela

That worked perfeclty.... Thank you very much.

Dan