# Calculate Age (Current date - Birth Date = Age Years)

Hello,

Is there any quick reference for calculating Age using a Birth Date and Current Date?  Both Date data type.

is it like this:  DiffDays(CurrDate(),BirtDate()) / 365

Appreciate any assistance.

Bye.

Hi Larry,

You can create your own server action and reuse it whenever you need it.

Also if you set function to Yes (since it will have one input and one output parameter), you can use it inside an expression

```If( Month(BirthDate)<Month(CurrDate()),
Year(CurrDate())-Year(BirthDate) - 1,
If( Month(BirthDate)=Month(CurrDate()) and Day(CurrDate())<Day(BirthDate),
Year(CurrDate())-Year(BirthDate) - 1,
Year(CurrDate())-Year(BirthDate)))```

Cheers

Thank you Andre - I will do that.

Hi - tanks for this snippet - I needed to adjust the second line. Otherwise it showed one year to low

From

`Year(CurrDate())-Year(BirthDate) - 1, `

To

`Year(CurrDate())-Year(BirthDate), `

André Rodrigues wrote:

Hi Larry,

You can create your own server action and reuse it whenever you need it.

Also if you set function to Yes (since it will have one input and one output parameter), you can use it inside an expression

```If( Month(BirthDate)<Month(CurrDate()),
Year(CurrDate())-Year(BirthDate) - 1,
If( Month(BirthDate)=Month(CurrDate()) and Day(CurrDate())<Day(BirthDate),
Year(CurrDate())-Year(BirthDate) - 1,
Year(CurrDate())-Year(BirthDate)))```

Cheers

Hi Andre,

Thanks for the snippet. But I think you have a mistake in the first line. The correct code should be:

```If(Month(CurrDate())<Month(BirthDate),
Year(CurrDate()) - Year(BirthDate) - 1,
If(Month(BirthDate)=Month(CurrDate()) and Day(CurrDate())<Day(BirthDate),
Year(CurrDate()) - Year(BirthDate) - 1,
Year(CurrDate()) - Year(BirthDate)))```

Cheers

Larry Mills wrote:

Hello,

Is there any quick reference for calculating Age using a Birth Date and Current Date?  Both Date data type.

is it like this:  DiffDays(CurrDate(),BirtDate()) / 365

Appreciate any assistance.

Bye.

Hi,

You can find function in Web Patterns named GetAge(Birthdate) where it returns the age.

Hope this is what you are looking for.

Thanks

Hi Larry Mills,

If any of the solutions worked for you then mark it as a solution so it may help others if they have any queries related to this.

Thanks

The code is still wrong, should be:

```If(Month(CurrDate())<Month(BirthDate),
Year(CurrDate()) - Year(BirthDate),
If(Month(BirthDate)=Month(CurrDate()) and Day(CurrDate())<Day(BirthDate),
Year(CurrDate()) - Year(BirthDate),
Year(CurrDate()) - Year(BirthDate) - 1))```